Jump to content

PHP working with SQL not printing results


nschmutz

Recommended Posts

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.

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?

Archived

This topic is now archived and is closed to further replies.

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