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 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    problem with mysql_num_rows() please help

    I noticed some errors in my paging so to check it I wrote this code using the same filters that I use on my tables .

    The first count - $tot_ads should equal the sum of
    the other two i.e. $tot_ads1 + $tot_ads2

    However they dont !

    I get
    $tot_ads = 57
    $tot_ads1 = 6
    $tot_ads2 = 52

    A seperate counter also counts 58 ads.

    Canu you spot where my problem might be ?

    PHP Code:
    $sql "SELECT * FROM $section
         WHERE confirm = 'y'
         AND offwant = '$N_ow'
         AND expire_date >= $today
         AND city = '$selt_city'"
    .$aug_area.$aug_cat;

         
    $result mysql_query($sql)
         or die (
    "Could not execute COUNT query.");

        
    $tot_ads mysql_num_rows($result);  // Number of adverts

            
    $sql "SELECT * FROM $section
            WHERE feature != ' '
            AND feature != ''
            AND confirm = 'y'
          AND offwant = '$N_ow'
          AND expire_date >= $today
            AND city = '$selt_city'"
    .$aug_area.$aug_cat." ORDER BY feature ";

            
    $result mysql_query($sql)
            or die (
    "Could not execute FEATURE query.");
            
         
    $tot_ads1 mysql_num_rows($result);  // Number of FEATURE adverts        
        
         
    $sql "SELECT * FROM $section
         WHERE feature = ' '
         OR feature = ''
         AND confirm = 'y'
         AND offwant = '$N_ow'
         AND expire_date >= $today
         AND city = '$selt_city'"
    .$aug_area.$aug_cat." ORDER BY $sorter";

         
    $result mysql_query($sql)
         or die (
    "Could not execute MAIN query.");

         
    $tot_ads2 mysql_num_rows($result);  // Number of NON FEATURE adverts 
    Thanks
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You probably need to use parenthesis to set the order of precedence on your conditional statements. The one with all "ands" is ok, the one with an "or" in there is probably not testing in the order you want.
    PHP Code:
        $sql "SELECT * FROM $section
         WHERE (feature = ' '
         OR feature = '')
         AND confirm = 'y'
         AND offwant = '$N_ow'
         AND expire_date >= $today
         AND city = '$selt_city'"
    .$aug_area.$aug_cat." ORDER BY $sorter"
    Of course, instead of using feature != ' ' and feature != '', you could use feature not in(' ', '')... same for feature = ' ' or feature = '', make it feature in(' ', '').

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks - I had a suspion it might be that OR
    anyway I used the in() and it works fine ...
    BUT the independant counter always counts one more than these
    num_rows() functions.

    eg on 1 tables my results now are:

    $tot_ads = 57
    $tot_ads1 = 6
    $tot_ads2 = 51

    When I count up the displayed rows on the screen
    I get 52 !

    Can I use that not in() within an if statement ?
    eg

    If ($feature not in(' ', '')){$row_style = "feature";}

    It looks pretty handy !

    AHHH - I tried it and it errored -
    what would be the best way to write the if statement then ??

    Thanks.
    Last edited by jeddi; 08-14-2006 at 08:36 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    See if you have any records with a null value for feature.

    Select * from yourtable where feature is null


  •  

    Posting Permissions

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