I hope this is the right place to put this!
I have a MySQL 4 database with 3 tables: orders, persons and products. These have fields as follows:
orders
ID
customer
date
Item1
Item2
(etc... there are 10 items)
products
ID
Item
Price
Category
SortOrder
persons
FirstName
Lastname
Middlename
City
Street
ZIPCode
Country
CellPhone
Homephone
Officephone
Email
Homepage
I am using the following query. Its purpose is to filter the results so we only get the orders that are to be delivered on a particular day of the week chosen from a calendar (i.e. $DelDate).
$result = mysql_query ("SELECT * FROM orders LEFT JOIN persons ON (persons.ID = orders.customer) WHERE DAYOFWEEK(date)=DAYOFWEEK(' . $DelDate . ')");
With this, I have a list of the items required and which customer they are for.
I am using this code:
if($total>0) {
$i = "Item";
// fetch the current row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
// print table header
echo("<table cellspacing=\"0\" cellpadding=\"0\" width=\"500\" class=\"edittable\">");
echo("<tr><td>" . $row["FirstName"] . " " . $row["Lastname"] . "</td></tr>");
for($j=1; $j<=10; $j++)
{
if ($row[$i.$j]>0)
{
echo("<tr><td>" . $row[$i.$j] . "x Item" . $j . "</td></tr>");
}
}
echo("<tr><td>" . $row["date"] . "</td></tr>");
echo("</table>");
echo("<br /><br />");
}
}
This outputs only the items where the quantity is greater than 0, so the result is something like:
Joe Bloggs
1x Item1
2x Item3
4x Item6
2008-05-08
However, I want the quantities to state what product it is, for example 2x Oranges. For this, I need it to look up the "Item" value from the "products" table.
Am I able to modify my query so that I can do this?
Thanks in advance!