We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,605 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

mysql_fetch_assoc() warning

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>
3
Contributors
4
Replies
2 Hours
Discussion Span
5 Months Ago
Last Updated
5
Views
Question
Answered
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

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.

pritaeas
Posting Prodigy
Moderator
9,263 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,455
Skill Endorsements: 86

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.

hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

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());
pritaeas
Posting Prodigy
Moderator
9,263 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,455
Skill Endorsements: 86

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.

diafol
Keep Smiling
Moderator
10,610 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
Question Answered as of 5 Months Ago by pritaeas and diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0680 seconds using 2.69MB