I have a query for category of items, in this example I have 2 WINEs from Chile. The code i have below works fine but only the foreach loop or whatever it is, it overlaps the first output with the second one.
I am new to for-each loop
Here is MY PHP:
<?php
include"db_connection.php";
$sql = mysql_query("SELECT * FROM WINE WHERE country='Chile'");
$allRows = array();
while($row = mysql_fetch_array($sql)) {
$allRows[] = $row;
}
foreach ($allRows as $row) {
$id = $row ["id"];
$description = $row["description"];
$wine_type = $row["wine_type"];
$country = $row["country"];
$bottle_price = $row["bottle_price"];
$indicator = $row["indicator"];
$colour = $row["colour"];
$case_price = $row["case_price"];
$case_size = $row["case_size"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}
?>
here is the HTML:
<?php include('header.php'); ?>
<div id="content">
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<?php
foreach ($allRows as $row) {
?>
<tr>
<td width="19%" valign="top"><img src="inventory_images/<?php echo $row['id']; ?>.jpg" width="142" height="188" alt="<?php echo $row['wine_type']; ?>" /><br />
<a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></td>
<td width="81%" valign="top"><h3><?php echo $wine_type; ?></h3>
<p><?php echo "$".$bottle_price; ?><br /><br />
<?php echo "$country $indicator"; ?> <br /><br />
<?php echo $description; ?> <br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php include('footer.php'); ?>