not displaying results correctly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scmeeker
Forum Newbie
Posts: 9
Joined: Sun Jun 13, 2010 5:37 pm

not displaying results correctly

Post by scmeeker »

On my web page, I'm trying to have a list of clickable links on the left side of the page and then when you click one of those links(categories), it will list the items associated with that category on right. I'm able to have the category links come up on the left...no problem. When I click the category the items drop below it and show all the specific items. I want it to show up in the right/middle of the page...so I moved the code appropriately. Now when I click a category link on the left it only shows the very LAST item in the database rather then all of them associated with the category.

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>";
				}
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: not displaying results correctly

Post by andyhoneycutt »

Could you post the code where you're actually echo'ing the results ($display_block)?
scmeeker
Forum Newbie
Posts: 9
Joined: Sun Jun 13, 2010 5:37 pm

Re: not displaying results correctly

Post by scmeeker »

I got this worked out...thanks!
Post Reply