www.webdeveloper.com
Results 1 to 2 of 2

Thread: I have a problem with my record counting !

  1. #1
    Join Date
    Jul 2004
    Location
    UK
    Posts
    518

    I have a problem with my record counting !

    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
    Developers Choice Revealed: www.devchoice.info
    Who has won, and why ?

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    what are you expecting the OR to OR between in the 3rd query? this is what your 3rd query reads in the SQL parser:

    $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";

    which i don't think is what you want...
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles