@Mark Byers below there is a simpler version of the code above and it has three if statement two before the else one inside a for each loop and another inside the for loop I want the one at the foreach loop to pair up with the else statement.
<?php
$totalCost=0;
foreach($result as $row)
{
if($row['ckb_id']){ if statement that will match the else statement..
// Increment the total cost of all items
$totalCost += ($row["qt_y"] * $row["price"]);
?>
<div id="cart1">
<select name="<?php echo $row["cdkb_id"];?>" onChange="UpdateQty(this)">
<?php print($row["cdkb_id"]);?>
<?php
for($i = 1; $i <= 30; $i++)
{
echo "<option ";
if($row["qt_y"] == $i) // if statement inside the for loop
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</div>
<div id="cart2">
<img src="images/logopic.gif"<?php /*?><?php echo $row["image"]; ?><?php */?> alt="we" width="60" height="50" />
</div>
<div id="cart3"><p><?php echo $row["name"]; ?></p></div>
<div id="cart4"><p>
$<?php echo number_format($row["price"], 2, ".", ","); ?></p></div>
<div id="cart5">
<p><?php
printf('<a href="cart.php?action=remove_item&id=%d&ids=%d®ister=%s">Remove</a>', $_GET['id'], $row['cdkb_id'], $_GET['register']);
?></p></div>
<hr size="1" color="red" >
<script language="JavaScript">
function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;
document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}
</script>
<?php
} // end of if statement
?>
<?php
else { // beginning of else statement
?>
<?php // Increment the total cost of all items
$totalCost += ($row["qt_y"] * $row["price2"]);
?>
<div id="cart1">
<select name="<?php echo $row["dkb_id"];?>" onChange="UpdateQty(this)">
<?php print($row["dkb_id"]);?>
<?php
for($i = 1; $i <= 30; $i++)
{
echo "<option ";
if($row["qt_y"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</div>
<div id="cart2">
<img src="images/logopic.gif"<?php /*?><?php echo $row["image2"]; ?><?php */?> alt="we" width="60" height="50" />
</div>
<div id="cart3"><p><?php echo $row["name2"]; ?></p></div>
<?php foreach ($row['dkb_id'] as $variety) {?>
<div id="cart4">
<?php echo"<p>".$variety['variety']. " ~ " . $variety['price3'] . "</p>" ?>
<p>$<?php echo number_format($row["price3"], 2, ".", ","); ?></p></div>
<?php } ?>
<div id="cart5">
<p><?php
printf('<a href="cart.php?action=remove_item&id=%d&ids=%d®ister=%s">Remove</a>', $_GET['id'], $row['dkb_id'], $_GET['register']);
?></p></div>
<hr size="1" color="red" >
<script language="JavaScript">
function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;
document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}
</script>
<font face="verdana" size="2" color="black" style="clear:right;">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b></font></td>
<?php } ?>
<?php } ?>
<div id="shopping">
<a href=<?php echo "exa2.php?id=".intval($id). '®ister='. $_GET['register']. ""?>> Keep Shopping</a></div>
<?php /*?><tr>
<td colspan="4">
<font face="verdana" size="1" color="black">
<a href=<?php echo "cart.php?id=".intval($id). '®ister='. $_GET['register']. ""?>>Your Shopping Cart</a></font></td>
</tr><?php */?>
</tr>
</table>
</table>