Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.