Jump to content

[SOLVED] while loop question


atticus

Recommended Posts

Noob Question:

I want to query mysql to produce the following flow:

-User1

  - User1 order1

  - User1 order2...

-User2

  - User2 order1

-User3

  - User3 order1

and so on...

 

My problem is that when I make the user a while, it displays all the names of the users and than displays the orders. 

 

This produces one User record correctly

$sql1 = "SELECT client.*,`order`.cust_id FROM `client`,`order` WHERE client.cust_id = `order`.cust_id";
$query1 = mysql_query($sql1);
$row = mysql_fetch_array($query1);
$id = $row['cust_id'];
echo $row['last_name'];

$sql = "SELECT * FROM `order` WHERE cust_id = $id ORDER BY time"; 
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<h4>".$row['last_name']." </h4><br />";

}
?>

How do I wrap the whole thing in a while so it repeats the user and second while again? 

 

 

Link to comment
https://forums.phpfreaks.com/topic/82742-solved-while-loop-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.