I'm a newbie to PHP and mySQL. Doing a simple on-line restaurant ordering system for a project.
With consideration to 2 tables that I have:
- ORDERS - holds orderid(primary key), userid(primary key in user table), total(total for billing), complete(flag for staff to set order as complete when processed), date
- ORDERSITIMISED - holds id(primary key), orderid(the key of ORDERS table), itemid(primary key in items table), and qty
I'm trying to have a loop which goes through each order in ORDERS and prints it to screen if its not set to 'COMPLETE'
Within each loop iteration I want to print the ordercontents from ORDERSITIMISED with orderid's that match the one in the main loop
I can print the list of orders no problem but having difficulty with printing the itemised list for each iteration. This is the error i get:
I've been trying various things and reading a good few tutorials but I'm obviously missing something fundamental here. Would i need to setup a join between tables and create a different query?
Code below:
<?php
session_start();
require('connect.php');
if ((@$_SESSION['adminflag'])==1){ //checks if adminflag is set to 1
echo "Welcome, ".$_SESSION['username']." to the live order view!<br><a href='logout.php'>Click here</a> to logout.";
echo "<h1>Live Orders</h1>";
//display orders
//get orders from orders table that are NOT complete
$get = mysql_query('SELECT * FROM orders WHERE complete=0');
if (mysql_num_rows($get)==0){
echo "<p>There are no active orders to display.";
}
else{
//for each order in the order table that is NOT complete...
while ($get_row = mysql_fetch_assoc($get)){
//extract user id and order id to be used to query other tables
$currentuserid = $get_row['userid'];
$currentorderid = $get_row['id'];
//print order id, date/time, and total due
echo "Order Number: $currentorderid. Timestamp: ".$get_row['date'].". Total Due: £".number_format($get_row['total'],2)."<p>";
//now for each iteration of the above while look, get all items from table 'ordersitemised' that have that orderid
$get_order = mysql_query('SELECT * FROM ordersitimised WHERE orderid=$currentorderid');
if (mysql_num_rows($get_order)==0){
echo "<p>No order details found for order# $currentorderid";
}
else{
while ($get_order_row = mysql_fetch_assoc($get_order)){
$currentitem = $get_details['itemid'];
$currentitemqty = $get_details['qty'];
echo "Item# $currentitem Qty:$currentitemqty";
}//end while
} //end else
}//end while
}//end else
}//end if
else{
//display unauthenticated message
die("You do not have permission to access this page!");
}
?>