...

View Full Version : problem with mysql_num_rows() please help



jeddi
08-14-2006, 04:12 PM
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 ?



$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

Fumigator
08-14-2006, 04:52 PM
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.


$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(' ', '').

jeddi
08-14-2006, 07:30 PM
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.

arnyinc
08-14-2006, 09:26 PM
See if you have any records with a null value for feature.

Select * from yourtable where feature is null



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum