atticus Posted December 21, 2007 Share Posted December 21, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82742-solved-while-loop-question/ Share on other sites More sharing options...
p2grace Posted December 21, 2007 Share Posted December 21, 2007 Try adding a group by in the query statement $sql1 = "SELECT client.*,`order`.cust_id FROM `client`,`order` WHERE client.cust_id = `order`.cust_id GROUP BY client.cust_id"; Quote Link to comment https://forums.phpfreaks.com/topic/82742-solved-while-loop-question/#findComment-420831 Share on other sites More sharing options...
atticus Posted December 21, 2007 Author Share Posted December 21, 2007 thanks for the help...worked perfectly the FIRST time. Quote Link to comment https://forums.phpfreaks.com/topic/82742-solved-while-loop-question/#findComment-420834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.