skoobi Posted February 10, 2010 Share Posted February 10, 2010 Hi im having a few problems with a query im doing... What im trying to do is to do a order page for a set food menu that when it is in the main screen it has starters, main course and deserts. If i go into the starters page i choose the meal i want and the qty; it updates the database and it then displays on the main menu under the starters link. At the moment its showing when theres not an order but not when there is an order. Heres the code... Ive tried all sorts of tutorials and googled but still cant figure it out... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Order Form</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php // CALL FOR NECESSARY FILES require_once 'includes/connect.php'; //TITLE echo '<p class="title">Order Form</p>'; // START OF STARTERS SECTION echo "<p class=\"body\"><a href=\"starters.php\">Starters</a><br/>"; // CALL THE ORDER FOR REVIEW FROM DATABASE mysql_select_db($db, $con); $result_starter = mysql_query("SELECT * FROM order_starter"); if (!$result_starter) { echo 'No Order Placed'; } else echo $row['qty'] . " - " . $row['starter'] ; echo "<br />"; echo "</p>"; // END OF STARTERS // START MAIN COURSE SECTION echo "<p class=\"body\"><a href=\"main_course.php\">Main Course</a><br/>"; // CALL THE MAIN COURSE ORDER FOR REVIEW FROM DATABASE mysql_select_db($db, $con); $result_main = mysql_query("SELECT * FROM order_main") ; if (mysql_num_rows($result_main)==0) { echo 'No Order Placed'; } else echo $row['qty'] . " - " . $row['main_course']; echo "<br /></p>"; // END OF MAIN COURSE // START DESERT SECTION echo "<p class=\"body\"><a href=\"main_course.php\">Deserts</a><br/>"; // CALL THE DESERT ORDER FOR REVIEW FROM DATABASE mysql_select_db($db, $con); $result_desert = mysql_query("SELECT * FROM order_desert"); if (mysql_num_rows($result_desert)==0) { echo 'No Order Placed'; } else echo $row['qty'] . " - " . $row['desert'] /*" | <a href=\"edit_desert.php\">Edit Order</a>"*/; echo "<br />"; mysql_close($con); echo '</p>'; // END OF DESERTS ?> </body> </html> If anyone can see what im doing wrong please let me know... Cheers Chris Link to comment https://forums.phpfreaks.com/topic/191660-database-query/ Share on other sites More sharing options...
wildteen88 Posted February 10, 2010 Share Posted February 10, 2010 You're not processing your results properly. mysql_query() only returns a result resource. In order to grab your results from your query you'll need to use one of the mysql_fetch_* functions, for example mysql_fetch_assoc $result_starter = mysql_query("SELECT * FROM order_starter"); if (!$result_starter) { echo 'No Order Placed'; } else { $row = mysql_fetch_assoc($result_starter); echo $row['qty'] . " - " . $row['starter'] ; echo "<br />"; } echo "</p>"; NOTE If your query returns more than one row you'll need to use a while loop instead $result_starter = mysql_query("SELECT * FROM order_starter"); if (!$result_starter) { echo 'No Order Placed'; } else { while($row = mysql_fetch_assoc($result_starter)) { echo $row['qty'] . " - " . $row['starter'] ; echo "<br />"; } } echo "</p>"; Link to comment https://forums.phpfreaks.com/topic/191660-database-query/#findComment-1010277 Share on other sites More sharing options...
skoobi Posted February 11, 2010 Author Share Posted February 11, 2010 Exellent thank you. thats exactly what i needed... Ive just baught a php mysql tutorial book so im going to delve into that over the next couple of days... Cheers Chris Link to comment https://forums.phpfreaks.com/topic/191660-database-query/#findComment-1010776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.