Page 1 of 1

not displaying results correctly

Posted: Tue Jun 15, 2010 3:34 pm
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>";
				}

Re: not displaying results correctly

Posted: Tue Jun 15, 2010 4:01 pm
by andyhoneycutt
Could you post the code where you're actually echo'ing the results ($display_block)?

Re: not displaying results correctly

Posted: Fri Jun 18, 2010 9:51 am
by scmeeker
I got this worked out...thanks!