nschmutz Posted June 28, 2010 Share Posted June 28, 2010 I was wondering if someone can look at my code and tell me why the results are not displaying. <html> <form action="schmutz_03_05.php" method="POST"> Please select a customer and a clerk: <p>Customer: <select name="customer"></p> <?php //creating the drop down menu with information from the database include ('mysql_connect_to_vandelay.php'); $query = "SELECT customer_id,CONCAT(customer_first_name, ' ',customer_last_name) AS customer_name FROM customers cu"; $result = mysql_query($query); //running query while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=" . $row['customer_id'] . ">" . $row['customer_name'] . "</option>"; } ?> </select> Clerk: <select name="clerk"> <?php include ('mysql_connect_to_vandelay.php'); $query = "SELECT clerk_id, CONCAT(clerk_first_name, ' ', clerk_last_name) AS clerk_name FROM clerks cl"; //make sure you have AS when combined with CONCAT $result = mysql_query($query); //running query while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=" . $row['clerk_id'] . ">" . $row['clerk_name'] . "</option>"; } //end of while statement ?> </select> <?php if (isset($_POST['submitted'])) { include ('mysql_connect_to_vandelay.php'); $sort_by=$_POST['sort_by']; // Build the query $query = "SELECT CONCAT(cu.customer_first_name, ' ', cu.customer_last_name) AS customer_name,CONCAT(cl.clerk_first_name, ' ', cl.clerk_last_name) AS clerk_name,SUM( ROUND(li.item_quantity * li.item_unit_price, 2) ) AS order_total,COUNT( DISTINCT o.order_id ) AS number_of_orders,ROUND(SUM( ROUND(li.item_quantity * li.item_unit_price, 2) ) / COUNT( DISTINCT o.order_id ), 2) AS average_order_total FROM orders o, clerks cl, customers cu, line_items li WHERE o.clerk_id=cl.clerk_id AND o.customer_id=cu.customer_id AND o.order_id=li.order_id AND CONCAT(cu.customer_first_name, ' ', cu.customer_last_name)='Peter Parker' AND CONCAT(cl.clerk_first_name, ' ', cl.clerk_last_name)='George Costanza'GROUP BY clerk_name, customer_name, order_total, number, numer_of_orders;"; //query to display names, total orders, #of orders and average order total $result = @mysql_query ($query); // Print the results echo '<table><tr><td>Customer Name:</td><td>Clerk Name:</td><td>Total of Orders:</td><td>Number of Orders:</td><td>Average order total:</td></tr>'; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<tr><td align="left">'.$row['customer_name'].'</td><td align="left">'.$row['clerk_name'].'</td><td align="left">'.$row['order_total'].'</td><td align="left">'.$row['number_of_orders'].'</td><td align="left">'.$row['average_order_total'].'</td></tr>'; } echo '<tr><td> </td><td> </td></tr> </table>'; } ?> <input type="submit" name="submit" value="List Orders" /> </form> </html> I appreciate any help. Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/ Share on other sites More sharing options...
conker87 Posted June 28, 2010 Share Posted June 28, 2010 Well, get rid of the @ next to the $result = @mysql_query ($query); So we can see any errors. Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078414 Share on other sites More sharing options...
nschmutz Posted June 28, 2010 Author Share Posted June 28, 2010 Nice catch conker87, I made the correction and no errors and it still is not displaying any results. Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078420 Share on other sites More sharing options...
conker87 Posted June 28, 2010 Share Posted June 28, 2010 Have you tried running the query in PHPMyDmin (or whatever mysql client you're using)? Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078426 Share on other sites More sharing options...
nschmutz Posted June 28, 2010 Author Share Posted June 28, 2010 I am running XAMPP which has Apache and MySql both running. I hope that answers your question conker87. Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078427 Share on other sites More sharing options...
nschmutz Posted June 28, 2010 Author Share Posted June 28, 2010 Does anyone know the solution to my problem of being able to display the results? Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078444 Share on other sites More sharing options...
kickstart Posted June 28, 2010 Share Posted June 28, 2010 Hi Run the SQL directly in phpmyadmin (I assume that XAMPP comes with it) to check that it actually brings anything back. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078451 Share on other sites More sharing options...
nschmutz Posted June 28, 2010 Author Share Posted June 28, 2010 Error MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<html> <form action="schmutz_03_05.php" method="POST"> Please select a cus' at line 1 This is the error message I get when running in the phpadmin. Does anyone know what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078491 Share on other sites More sharing options...
kenrbnsn Posted June 29, 2010 Share Posted June 29, 2010 You should be only running the query in phpmyadmin, not you whole script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206111-php-working-with-sql-not-printing-results/#findComment-1078520 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.