nesting mysql queries?

Codes here !

Moderators: egami, macek, gesf

Post Reply

Thu Aug 08, 2002 6:40 pm

Two ways of doing this. One is when you're printing a row for the products, you can perform a second query to display the additive. However, this is very inefficient as it requires many queries to be performed.

The easiest way is to use table joins to get all the data out in one go. I can't advise you 'cos I don't know the setup of your db or what you're trying to access.

If you've already explored this option and joins can't be created, then I'd advise running 2 queries first if that's possible. And then create an array based on the results and output the Array.


Fri Aug 09, 2002 5:10 pm

The easiest would be to learn how Arrays work. Best to read a good book. But in short, an array is a variable made up of two basic values:
$variable = array($key => $value);

The $value is returned when you access $variable[$key];

The $value can be an array too, which is how you get multi-dimensional arrays eg

$ford = ("Puma" => array("Price" => 12000,"Engine" => 1.7))

To get the price you'd use $ford["Puma"]["Price"];

Notice the Puma array has 2 array values (Price and Engine). You can have as many as you want in an array.

Like I said, best think is to learn how they work, and then use the arrays to print your table. It's almost the same as printing a row for each mysql_fetch_array(); except you're using an array


Sat Aug 10, 2002 10:56 am

I read a book called 'A Programmers Introduction to PHP 4.0' which I thought was very good. I was a complete beginner and it was very simple to understand. It's be Apress and the author is WJ Gilmore. It's nearly year old now so I don't know if it'll be available.

I also bought another book called 'Building Dynamic Pages Using PHP and MySQL' by David Tansley. I bought that one originally (and the one above on the spur of the moment, dunno why), but it turned out to be very bad and basic!

The best thing to do is read a few books, and try and get the best you can afford. But read them to see what style suits you. The WJ Gilmore book basically gave a break down of all the functions and how they could be used, which I thought was very useful as I could instantly see whether a function would be suitable for me. The David Tansley book was very basic, almost for babies. It didn't contain enough detail and left many questions unanswered

So, my advise is to read a few chapters, and decide which style you like.

Post Reply