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 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    will there be results in mysql_query?

    PHP Code:
    <?PHP
                 $link 
    mysql_connect ($Host$User$Password);  
        
    mysql_select_db($DBName$link);

        
    $Query "SELECT * FROM $_GET[$Cat]";
        
    $Result mysql_query ($Query);
    ?>
    Will there be a $Result if that php scripting section is done? Then I start another one IE:

    PHP Code:
    <?php 
         
    while ($Row mysql_fetch_array($Result)) {
              print (
    "<ul><li>$Row[Category]</li>");
         }
         
    mysql_close ($Link);
         print (
    "</ul>");
    ?>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Will there be a $Result if that php scripting section is done? Then I start another one IE:
    Well, how would we know ?

    If the rest of your code is correct (so if all these variables are set correctly) and if there are records inside tat table, the $Result will contain a resourceID.

    Your <ul> tag should be outside the loop, by the way
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    you can check with mysql_num_rows() , the '@' supresses error messages

    PHP Code:
    <?
    if( @mysql_num_rows$Result ) ){
     echo 
    '<ul>' ;
     while ( 
    $Row mysql_fetch_assoc$Result ) ) {
              echo 
    "<li>{$Row['Category']}</li>" ;
         }
        echo 
    '</ul>' 
    }else{
        echo 
    'Query result was empty' ;
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Jun 2003
    Location
    Massachusetts
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mysql_num_rows ALWAYS returns TRUE.

    if there are no results, mysql_num_rows will return 0, not FALSE.

    so using if(mysql_num_rows($result)){ } will always evaluate as true, unless the query failed (if the query did fail it would output an error message anyway...)

    if(mysql_num_rows($result) > 0){ } on the other hand, will only return true if there is at least 1 row in the result.
    Last edited by SmArTaSs; 05-09-2004 at 08:17 PM.
    -Matt

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You've chose a nickname that realy fits you.

    and you're prooving you:
    - don't know much about PHP and how it's conditional evaluations work, because 0 is often evaluated as False
    - did not tried the code that was given to you by a far more experience coder then you are.

    So it might be a good idea to get your facts straight before starting to lecture here.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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