Paul M Foster wrote: > On Mon, Mar 16, 2009 at 03:46:29PM -0500, PJ wrote: > > <snip> > > >>>> $book_publisher = array(); >>>> $SQL = "SELECT id, bookID, publisher_id FROM book_publisher"; >>>> if ( ( $results = mysql_query($SQL, $db) ) !== false ) { >>>> while ( $row = mysql_fetch_assoc($results) ) { >>>> $book_publisher[$row['bookID']][] = $row['publisher_id']; >>>> >> Could you explain this, please - this is further from me than Arcturus: >> $book_publisher[$row['bookID']][] = $row['publisher_id']; >> What is purpose and meaning of all the [] brackets? Especially the empty >> ones? >> I following your example, I have been able to finally get all the arrays >> in place. Only now, I am looking into how to retrieve the parts of the >> array... >> > > PJ, you *really* need to read up on the *basics* of the PHP language. > Please buy a good book on the subject, or search php.net for "arrays" > and read and understand what is there. > > To summarize, $book_publisher is an array, as you can tell by the > square brackets after it. Its first index is book IDs. So in the > expression $book_publisher[$row['bookID']], $row['bookID'] is the > "index" for one of the members of the array. It could be 5 instead, as > in: $book_publisher[5]. > > Likewise, $row is an array. When you see an expression like > $array['something'] or $array[1], the value being represented is > actually the value at that index of the array. If you have an array of > letters called "$alphabet", it might look something like this: > > indexes: 'a', 'b', 'c', 'd', 'e' > contents: 'alfa', 'bravo', 'charlie', 'delta', 'echo' > > So if you had an expression like: $alphabet['d'], it would actually > represent the value 'delta'. Read the above until that's clear. > > In the case of $row['bookID'], it's just a value at the 'bookID' index > of the $row array. It could be '1234', '55-345' or whatever. > > So $book_publisher[$row['bookID']] is the array member at the > $row['bookID'] index of the array. > > Lastly, since an array member can also be another array, you can have > "multidimensional arrays". In your case, it's: > > $book_publisher[$row['bookID']][] > > Notice the last set of open and close backets on the end. That tells you > that $book_publisher[$row['bookID']] is an array member which is > actually another array. But empty open/close brackets have a special > meaning. You will only find them (meaningfully) on the left hand side of > an equation. They mean that you're adding whatever is on the right side > of the equation to the last position in the array. So > > $book_publisher[$row['bookID']][] = $row['publisher_id'] > > Says that the $row['bookID'] member of $book_publisher is an array, and > that you're adding a member on the end whose value is > $row['publisher_id']. > > Depending on your mental abilities, you may have to draw the arrays on a > sheet of paper to make it make sense. Also remember that arrays can be > indexed either numerically or "associatively" or both. A numerically > indexed arrays would have just numbers for the indexes. An associatively > indexed array is what you have above, indexed not necessarily by number > but possibly by strings or whatever. > > All this is fundamental to array processing under PHP and used > constantly. So learn it and learn it well. If my explanation is > insufficient, then look it up and fully understand it before you go on. > Otherwise, you'll take one step, ask a bunch of questions, take another > step, ask a bunch of questions, and generally make yourself a nuisance. > You're essentially asking professional programmers to tutor you for free > when you really should take the initiative and read/study the subject > yourself. It doesn't matter if you don't really want to *be* a > professional programmer at the end of this. You have to approach it as > though that's your goal. > > Let me put this another way. Assume you're a professional chef. You get > paid lots of money to cook food for people. You've had years of > education and practice and get paid accordingly. Suddenly one day, > management sends you some wet-behind-the-ears kid who's flipped burgers > at McDonalds, and you're supposed to teach him how to cook like you do. > Every time he cuts a shallot or dices an onion, he asks you a bunch of > silly questions he should know if he had gone to culinary school like > you did. You're busy. And the questions are things like "What's the > difference between a teaspoon and a tablespoon?". "How come I have to > dice onions? Can't I just throw them in the pot?" And you know that the > only reason the kid is there is so he can learn to cook some stuff to > impress his girlfriend, who's gonna dump him in three months anyway. > Think about it. > > Paul > Thanks Paul for the explanation. It really does help and iis much appreciated. I must respond to your chastisement of me, because i believe you may not be aware of the fact that most books on programming really suck. I have had my taste of enough of them to not bother. The kinds of things that I am trying to do just cannot be learned from a book or from most of those "tutorials" one finds on the Internet. They are either moronically basic of sadly flawed or outdated. It's something like the do-it-yourself-wikis... any dolt can put of whatever they think. That's the downside of the net, of course. The upside is that there are great people, like yourself and a number of other who have been very helpful and who are willing to share their knowledge. Anyway, I find very little in the tutorials on the web that goes beyond total basics. You really have to have been immersed in arrays and joins and all that stuff. I'm learning more and more as I go along. Without help from people like yourself, I would have give up long ago and gone fishing or something as useless as that. And really, that is the essence of greatness whether it be a programmer, a great chef, or a coach like Vince Lombardi. The essence of the matter is to share the knowledge and give pleasure to others. I have met and worked with some of the truly greats like Lombardi and most of the great French chefs. They all shared those same qualities. You didn't pick the the right analogy, food... that is one of the areas I have been involved in for decades along with my wife who is not only a great chef but also a communicator and incredible personality. take a look at http://www.chiccantine.com/andypantry.php That's some of my work - the photography. Not as good as I would have liked, but llimited by $$$. We have done films, tv shows, books, etc. etc.... You cannot compare the food industry with computer programming. It is far easier to do something in the food industry than in about anything else. You should get a closer look at all that. And it just is not in books. My wife is managing a couple of what are supposed to be the best corporate restaurants in Canada... you would not believe the truth of things... she is writing a book on that - not only is the situation in food pathetic but hilarious as well. You kind of have to wonder why we as "intelligent human beings" accept that the food industry (industry, does that sound a bell somewhere) has the lowes paid workers and that the quality of food that is thrown at us is really close to horrendous... oh, well, don't look too closely into your dish, you may find someone looking back at you... or something... :-D The food industry is sort of at the rectal end of the enteron wheras programming takes quite a bit of intellectual prowess. I'm just blabbering at this point as it's been a long day and I'm just whacked-out. Have a good night. -- unheralded genius: "A clean desk is the sign of a dull mind. " ------------------------------------------------------------- Phil Jourdan --- pj@xxxxxxxxxxxxx http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php