So I'm wondering how I can make it show all the items rather than just the last one when I move the code to a different part of the page.
Here is my code:
Code: Select all
//show categories first
$get_cats_sql = "SELECT cat_id, cat_title FROM category ORDER BY cat_id";
$get_cats_res = mysqli_query($mysqli, $get_cats_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_cats_res) < 1) {
$display_block = "<p><em>Sorry, no categories to browse.</em></p>";
} else {
while ($cats = mysqli_fetch_array($get_cats_res)) {
$cat_id = $cats['cat_id'];
$cat_title = ($cats['cat_title']);
$display_block .= "<a href=\"".$_SERVER["PHP_SELF"]."?cat_id=".$cat_id."\">".$cat_title." <br /></a>";
if (isset($_GET["cat_id"])) {
if ($_GET["cat_id"] == $cat_id) {
//get items
$get_items_sql = "SELECT id, photo, title, price FROM product WHERE cat_id = '".$cat_id."' ORDER BY date";
$get_items_res = mysqli_query($mysqli, $get_items_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_items_res) < 1) {
$display_block = "<p><em>Sorry, no items in this category.</em></p>";
} else {
$display_block .= "<ul>";
while ($items = mysqli_fetch_array($get_items_res)) {
$item_id = $items['id'];
$item_photo = $items['photo'];
$item_title = stripslashes($items['title']);
$item_price = $items['price'];
$display_block .= "<a href=\"items3.php?id=".$item_id."\">".$item_title."</a></strong> (\$".$item_price.")</li>";
}
$display_block .= "</ul>";
}