Mr Chris Posted July 31, 2009 Share Posted July 31, 2009 Hi, Scratching my head a little here... :-( I have a while loop which contains a query. If I run the query in MYSQL I get two results returned, but if I run it in php I get 1 result returned and its like my while loop is not working. Anyone see anything obvious below as to why the code does not loop - or if there is some kind of issue with the query that would stop this looping: Thanks $sql_one = " SELECT * FROM orders, names WHERE names.order_code =$order_code AND orders.order_code =$order_code ORDER BY orders.id"; $result_one = mysql_query($sql_one) or die(mysql_error()); $row = mysql_fetch_array($result_one); $your_name = $row['your_name']; $your_email = $row['your_email']; //Send email $message = "Dear ".$your_name."\n\nYou have now confirmed your order:\n\n"; $n=1; while ($row = mysql_fetch_assoc($result_one)) { $item_name = $row['item_name']; $amount = $row['amount']; $quantity = $row['quantity']; $total_price = $row['total_product_price']; $message .= "Product: ".$item_name."\n"; $message .= "Product Price: ".$amount."\n"; $message .= "Quantity: ".$quantity."\n"; $message .= "Total Product Price: ".$total_price."\n\n"; $n++; } Link to comment https://forums.phpfreaks.com/topic/168308-while-loopquery-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 31, 2009 Share Posted July 31, 2009 The following line of code, immediately after the line with the mysql_query() statement, is fetching the first row from the result set and is only using the name and email from it. The rest of that row is being discarded - $row = mysql_fetch_array($result_one); Link to comment https://forums.phpfreaks.com/topic/168308-while-loopquery-help/#findComment-887760 Share on other sites More sharing options...
Mardoxx Posted July 31, 2009 Share Posted July 31, 2009 mysql_data_seek ($result_one, 0); after $n=1; Link to comment https://forums.phpfreaks.com/topic/168308-while-loopquery-help/#findComment-887939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.