Multiple Rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danh
Forum Newbie
Posts: 1
Joined: Tue Aug 03, 2010 4:35 am

Multiple Rows

Post by danh »

Hi all, I'm having some problems querying multiple rows in a table. I would massively appreciate it if someone could just take a quick look at my code and tell me where I've gone wrong.

Code: Select all

                  $result = mysql_query("select filling_id from order_filling where order_id = 1");
                  while ($of = mysql_fetch_array($result))
                  {
                      $result = mysql_query("select * from filling where filling_id = $of[0]");
                      $filling = mysql_fetch_array($result);
                      $filling_string = $filling[name] . ", " . $filling_string;
                  }
Many thanks in advance
Dan
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Multiple Rows

Post by jraede »

There is absolutely no reason why you need two queries...you can get all the information you need in the original query. Try this:

Code: Select all

$result = mysql_query("SELECT `filling`.* FROM `order_filling` INNER JOIN `filling` ON `order_filling`.`filling_id`=`filling`.`filling_id` WHERE `order_filling`.`order_id` = '1'");
                  while ($filling = mysql_fetch_array($result))
                  {
                      $filling_string = $filling['name'] . ", " . $filling_string;
                  }
Post Reply