1,105,363 Community Members

mysql_fetch_assoc() warning

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
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>
Member Avatar
pritaeas
mod_pritaeas
11,291 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
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.

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
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.

Member Avatar
pritaeas
mod_pritaeas
11,291 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
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());
Member Avatar
diafol
Where are my eyes?
12,943 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
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
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article