php - MySQL query and get id values -


thanks dropping by!

i trying e-commerce website school project. purpose populate webpages content database , 1 specific conditional don't seem recorded me able pull data out db presented on website:

one main page have code on residing on sidebar: leads php page retrieve products base on product category

  <ul class="left_menu">     <li class="odd"><a href="categories.php?catno=10familia">familia originals</a></li>     <li class="even"><a href="categories.php?catno=20familia">ready cook</a></li>     <li class="odd"><a href="categories.php?catno=30familia">siomai , buns</a></li>     <li class="even"><a href="categories.php?catno=40familia">pork snacks</a></li>     <li class="odd"><a href="categories.php?catno=50familia">ready made dishes</a></li>   </ul> 

and have code/page present products base on product category using (id)catno= reference category should displayed.

// sanitize $_get['catno'] , match correct category: $sanitize = mysqli_real_escape_string($dbc, $_get['catno']);  //match cases according product category if ($sanitize == '10familia') { $catid = 1; } elseif ($sanitize == '20familia') { $catid = 2; } elseif ($sanitize == '30familia') { $catid = 3; } elseif ($sanitize == '40familia') { $catid = 4; } elseif ($sanitize == '50familia') { $catid = 5; } else { $cat_error = '<div class="center"><h2>there no products in category. please try again later.</h2></div>'; } ?> <div class="center_content"> <div class="center_title_bar">latest products</div> <div class="scroll_box_tall">     <?     $query = "select product_id, name, price, thumbnail products category_id = '$catid' order product_id asc";     $request = mysqli_query($dbc, $query);      if (mysqli_affected_rows($dbc) == 1) {         while ($row = mysqli_fetch_array($request, mysqli_num)) {             $item_id = $row[0]; // assign product_id $item_id passed on href             $item_name = $row[1]; // assign name var $item_name             $item_price = $row[2]; // assign price var $item_price             $item_thumb = $row[3]; // assign thumbnail $item_thumb             // echo item name             $div1 = '<div class="prod_box"><div class="top_prod_box"></div><div class="center_prod_box"><div class="product_title">' . $item_name . '</div>';             // echo thumbnail             $div2 = '<div class="product_img"><a href="show_product.php?idno=' . $item_id . '"><img src="product/thumb/' . $item_thumb . '" alt="' . $item_name . '"/></a></div>';             // echo price             $div3 = '<div class="prod_price"><span class="price">rrp &pound; ' . $item_price . '</span></div></div><div class="bottom_prod_box"></div></div>';             echo "$div1$div2$div3";         }     } else { // error message if there no products in category or query unsuccessful         echo '<div class="center"><h2>there no products in category. please try again later.</h2></div>';     } ?> </div> 

the conditionals if/else working fine , works in retrieving products , showing on page. (categories($catid) 2,3,4,5 - working fine if they're respective links clicked) main problem conditionals if/else records value except first one:

if ($sanitize == '10familia') { $catid = 1; } 

the value $catid= 1 not being recorded query pull products category 1 in database.

i don't know why specific conditional won't work other 4 identical works..

note: started php , apologize if there better way if-else , did if/elseif approach.

thank all. :)

just guess because there's no information on test data, looks suspect:

if (mysqli_affected_rows($dbc) == 1) { 

this checks see if exactly 1 row returned query. possible test data has 1 row categories 2 through 5 , more 1 row category 1? try changing logic this:

if (mysqli_affected_rows($dbc) > 0) { 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -