Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    94
    Thanks
    23
    Thanked 0 Times in 0 Posts

    SQL SELECT query help

    Hi,

    I'm trying to do a straightforward SELECT query but I can't work out what I'm doing wrong.

    My database table looks like this -

    SQL SELECT query help-screenshot-2014-04-06-17.43.56.jpg

    I'm trying to print out the category, then the skills in the category nested underneath it, e.g -

    Writing and Journalism

    Articles
    Blogs
    Fiction

    Web Development, IT and Computing

    Database Design
    E-Commerce Set Up
    Game Developing

    etc.

    Here is the code I'm using -

    PHP Code:
             <?php
                            
             $test_two 
    mysqli_query($con,"SELECT DISTINCT cat FROM skills");
             
             while(
    $testrowtwo mysqli_fetch_array($test_two))
     
             {
             
             
    $cat $testrowtwo['cat']; //prints out categories okay
             
             
    echo '<strong>' .$cat'</strong><br />';
                 
             
    $result mysql_query("SELECT skill from skills WHERE cat = ".$cat."");
             
             while (
    $row mysql_fetch_assoc($result)) { //line producing warning
                 
             
    print_r($row);
             
             }
                
             }
             
             
    ?>
    This is printing the category headers okay, but underneath each category heading I get the following warning

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

    ..From the line containing the second while

    What am I doing wrong? Any help appreciated!

    Thanks

  • #2
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Try something like:

    Code:
    $result = mysql_query("SELECT skill from skills WHERE cat = \"".$cat."\"");

  • Users who have thanked Linux_Sage for this post:

    swiltch (04-06-2014)

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    94
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Thanks a lot!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •