I am sorry for the long pieces of code. I have to pieces of code and sort of want to merge them. I want to accomplish two things.
1) For each item that is in the $_SESSION['order'] array and in the "items" database table, I need to create an input field with a value like in the second piece of code posted below (about 20 lines down).
2) For each item that is in the array and not in the "items" database table, I need to create a hidden field like in the first piece of code below.
I have tried many different foreach() loops and I am having difficulty getting this to work the right way. Any guidance would be greatly appreciated.
Thanks in advance.
if(!empty($_SESSION['order'])) {
foreach($_SESSION['order'] as $key => $value) {
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
}
}
$itemsSql = "SELECT * FROM items WHERE menu = '$categoryMenu' AND category = '$category'";
$itemsRows = $db->getAll($itemsSql);
echo "<table border=\"0\" width=\"541\" id=\"table1\">
<tr>
<td colspan=\"3\" height=\"34\" valign=\"top\"><b>
<font face=\"Times New Roman\" color=\"#990000\">$category:</font></b></td>
</tr>";
if(!empty($_SESSION['order'])) {
foreach($_SESSION['order'] as $key => $value) {
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
}
}
foreach ($itemsRows as $itemsRow) {
$itemId = $itemsRow['itemId'];
$itemName = $itemsRow['itemName'];
$temperature = $itemsRow['temperature'];
$itemDescription = $itemsRow['itemDescription'];
$price = $itemsRow['price'];
echo "<tr>
<td width=\"24\" valign=\"top\" align=\"center\"><input type=\"text\" size=\"3\" name=\"$itemId\" value=\"$value\"></td>
<td width=\"421\" valign=\"top\">
<span style=\"font-family: Times New Roman\">
<font size=\"2\" color=\"#3F1F08\">$itemName</font></span></td>";
if($itemDescription != ""){
echo "<td width=\"421\" valign=\"top\">
<span style=\"font-family: Times New Roman\">
<font size=\"2\" color=\"#3F1F08\">$itemDescription</font></span></td>";
}
echo "<td width=\"82\" align=\"right\" valign=\"top\">
<font face=\"Times New Roman\" size=\"2\" color=\"#3F1F08\">$$price</font></td>
</tr>";
}
echo "</table>";
}