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>

Recommended Answers

All 4 Replies

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.

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.

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());
Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.