Can anyone help me out with this one, I am wanting to print out all entries from the database that match a specific genre.
For some reason I am only getting the first entry from each genre printed off, but I want it to print all of them accordinly.
I have a while statement within the code, so where am I going wrong:
//SQL query
if ($genre != "" ) {
$sql = "SELECT FROM PRODUCT WHERE genre =\"$genre\"";
} else {
$sql = "SELECT FROM PRODUCT WHERE product_id = \"$product_id\"";
}
//Execute SQL and exit if failure
$sql_result = mysql_query($sql, $connection) or die ("Sorry the query could not be executed");
while ($row = mysql_fetch_array($sql_result)){
$product_id = $row["product_id"];
$type = $row["type"];
$genre = $row["genre"];
$title = $row["title"];
$picture = $row["picture"];
$description = $row["description"];
$audio = $row["audio"];
$availability = $row["availability"];
$price = $row["price"];
}
?>
<head>
<link rel="stylesheet" href="../home_files/home_styles.css" type="text/css">
</head>
<body bgcolor="#666666">
<h1 align=center class="dbgeneral">Product Details</h1>
<table align=center>
<tr>
<td class="dbgeneral"><b>Title:</b></td>
<td> <span class="dbgeneral">
<?print $title;?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Product_ID:</b></td>
<td> <span class="dbgeneral">
<?php echo $product_id;?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Product Image:</b></td>
<td> <span class="dbgeneral">
<?php
if(!$picture){
echo "Sorry no picture currently available";
} else {
echo "<img src=\"$picture\">";
}
?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Genre:</b></td>
<td> <span class="dbgeneral">
<?php echo "$genre";?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Description:</b></td>
<td> <span class="dbgeneral">
<?php echo "$description";?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Audio:</b></td>
<td> <span class="dbgeneral">
<?php
if(!$audio){
echo "Sorry no audio currently available";
} else {
echo "<a href=\"$audio\">Play</a>";
}
?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Availability:</b></td>
<td> <span class="dbgeneral">
<?php echo "$availability";?>
</span></td>
</tr>
<tr>
<td class="dbgeneral"><b>Price:</b></td>
<td> <span class="dbgeneral">
<?php echo "$price";?>
</span></td>
</tr>
</table>
<form method="post" action="addtocart.php">
<span class="dbgeneral">
<input type="hidden" name="sel_item" value="<?php echo "$product_id";?>">
<input type="hidden" name="sel_item_title" value="<?php echo "$title";?>">
<input type="hidden" name="sel_item_price" value="<?php echo "$price";?>">
</span>
<center>
<span class="dbgeneral"><em>Quantity</em>
<input type="text" name="sel_item_qty" value="1" size=3>
</span>
<p> <span class="dbgeneral">
<input type="submit" name="submit" value="Add to shopping cart">
</span></p>
</center>
</form>
</body>