hiya ...
iam a bit unsure of what you want and the table-structure you use ...
i'm just guessing now ...
$SQLstring = "SELECT id, category FROM $TableName ORDER by category asc";
results in product-ids and their corresponding category ??
if so, then you may change
THIS:
. . .
$SQLstring = "SELECT id, category FROM $TableName ORDER by category asc";
. . .
<FORM method=\"POST\" action=\"viewbycat.php\">
<select name=\"sel_record\">
<option value=\"\"> -- Choose a Category -- </option>";
while ($row = mysqli_fetch_array($QueryResult)) {
$id = $row["id"];
$category = $row["category"];
echo "<option value=\"$id\">$category</option>";
}
echo "
</select> <INPUT type=\"submit\" value=\"Go\"></p>
<br />
</FORM>
into THIS:
. . .
$SQLstring = "SELECT DISTINCT(category) AS _category FROM $TableName ORDER by _category asc";
. . .
<FORM method=\"POST\" action=\"viewbycat.php\">
<select name=\"sel_record\">
<option value=\"\"> -- Choose a Category -- </option>";
while ($row = mysqli_fetch_array($QueryResult)) {
$category = $row["category"];
echo "<option value=\"$category\">$category</option>";
}
echo "
</select> <INPUT type=\"submit\" value=\"Go\"></p>
<br />
</FORM>
and THIS:
and a snippet from my view page:
. . .
$category=$_GET['category'];
$id=$_GET['id'];
// formulate and execute the query
$getCats = "SELECT * FROM $TableName WHERE id = '$_POST[sel_record]'";
$getCats_res = mysqli_query($DBConnect, $getCats) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) ."</p>";
if (mysqli_num_rows($getCats_res) < 1) {
//invalid item
$display_block = "<p>Sorry, no categories exist!</p>";
} else {
//categories exist, so get them and then get information
while ($cat_row = mysqli_fetch_array($getCats_res)) {
$category = stripslashes($cat_row['category']);
//now start the display_block and then get items
$id = $cat_row['id'];
$ProductName = stripslashes($cat_row['product_name']);
/*$Description = stripslashes($cat_row['description']);*/
$Price = stripslashes($cat_row['price']);
$thumb = stripslashes($cat_row['thumbnail']);
$display_block .= "<table width=\"585\">
<tr align=\"center\">
<td width=\"72\" valign=\"middle\"><a href=\"shop_xxx.php?id=$id\"><img src=\"$thumb\"></td>
<td width=\"350\" valign=\"middle\"><a href=\"shop_xxx.php?id=$id\"><p><strong>$ProductName</strong></a></p></td>
<td width=\"72\" valign=\"middle\"><p class=\"body\"><strong> $Price</strong></p></td>
</tr>
</table>";
}
}
?>
into THIS:
and a snippet from my view page:
. . .
$category=$_GET['category'];
// formulate and execute the query
$getCats = "SELECT * FROM $TableName WHERE category = '$category'";
$getCats_res = mysqli_query($DBConnect, $getCats) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) ."</p>";
if (mysqli_num_rows($getCats_res) < 1) {
//invalid item
$display_block = "<p>Sorry, no categories exist!</p>";
} else {
//categories exist, so get them and then get information
while ($cat_row = mysqli_fetch_array($getCats_res)) {
$category = stripslashes($cat_row['category']);
//now start the display_block and then get items
$id = $cat_row['id'];
$ProductName = stripslashes($cat_row['product_name']);
/*$Description = stripslashes($cat_row['description']);*/
$Price = stripslashes($cat_row['price']);
$thumb = stripslashes($cat_row['thumbnail']);
$display_block .= "<table width=\"585\">
<tr align=\"center\">
<td width=\"72\" valign=\"middle\"><a href=\"shop_xxx.php?id=$id\"><img src=\"$thumb\"></td>
<td width=\"350\" valign=\"middle\"><a href=\"shop_xxx.php?id=$id\"><p><strong>$ProductName</strong></a></p></td>
<td width=\"72\" valign=\"middle\"><p class=\"body\"><strong> $Price</strong></p></td>
</tr>
</table>";
}
}
?>
this may help you on this problem, but i noticed some other stuff:
beware of code like this:
$id=$_GET['id'];
this is prone to a sql-injection attack !!!
btw: i also noticed this:
echo "<FORM method=\"POST\" action=\"viewbycat.php\">"
is not directly wrong ... but hard to read ( @ least for me )
i think its better to use
echo '<FORM method="POST" action="viewbycat.php">';
or ... when using variables
echo '<a href="shop_xxx.php?id='.$id.'"><p><strong>'.$ProductName.'</strong></a>';