1.11M Members

mysql_fetch_assoc() warning

 
0
 

geeting a error
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\E_COMMERCE\MENU_PAGES\apparel_pages\male_print_image.php on line 35

line 35: while($row = mysql_fetch_assoc($item_query))

<?php
...
     if(isset($_POST['male_button'])) 
       {
          $order_by_p  = $_POST['order_by'];             
          if($order_by_p == 'heigh_low')
           {
            $item_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' ORDER BY id DESC LIMIT 8"); 
            }                
         }
         else
        {
           $item_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' LIMIT 8"); 
        }

                    while($row = mysql_fetch_assoc($item_query))
                    {
                    .....

===============

form page

<form action='male_print_image.php' method='POST'>
              <label>Sub Category:</label> 
               <select  name="order_by">
                 <option value="">Choose...</option>
                   <option value="most_popular">Most Popular</option>
                  <option value="title">Title</option>
                 <option value="newest">Newest</option>
                  <option value="oldest">Oldest</option>
                  <option value="low_heigh">Price: Low to Heigh</option>
                  <option value="heigh_low">Price: Height to Low</option>
                </select>

              <div id="submit">
                        <button type="submit" id="male_button" class="button" name="male_button">go</button>
              </div> 
            </form>
 
1
 

That would mean the query failed. It looks correct at first glance, so are you sure you are connected correctly? I suggest you add some error checking to find out.

 
0
 

yes iam connect to database. i just puted some error. and this one is not working:

 $item_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' ORDER BY id DESC LIMIT 8");

but this query works fine:

$item_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' LIMIT 8");

also note if i switch two query than the 2nd one will work. for some resone the one in if statment doesnt work.

 
1
 

Are you sure there is an id column in the item table?

Do this:

$item_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' ORDER BY id DESC LIMIT 8") or die(mysql_error());
 
1
 

From where I'm looking, this table looks a bit awkward. I'd make the sub_category field an integer related to a subcategories table.

Question Answered as of 1 Year Ago by pritaeas and diafol
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article