Jump to content

[SOLVED] Count


DrTrans

Recommended Posts

Getting the same count everytime

 


$visitquery = mysql_query("SELECT COUNT(*) FROM visitors WHERE ownerkey = '$uuid' & region = '$selected' AND `date` < DATE_ADD(CURDATE(), INTERVAL +7 DAY)", $connect);
$row9 = mysql_fetch_array($visitquery); 
$visitoramount = $row9[0];
 print "[$visitoramount] visits in the last 7 days!";

If $selected = "Blah" it gives the count as " 8"

if $selected = "Dumb" it gives the count as "8" ... Al though there is no "Dumb" in the db.

 

Sorry if my explaining is off. Just dont know another way to explain it easier.

Link to comment
https://forums.phpfreaks.com/topic/179305-solved-count/
Share on other sites

I don't think you can use the '&' in a WHERE clause, change that to AND:

$visitquery = mysql_query("SELECT COUNT(*) FROM visitors WHERE ownerkey = '$uuid' AND region = '$selected' AND `date` < DATE_ADD(CURDATE(), INTERVAL +7 DAY)", $connect);

 

By the way, shouldn't that be "date > CURDATE - 7" ?  I mean if you are looking for the number of visits in the past seven days.  Your query specifies all dates less than NEXT WEEK; that would probably be all of them.

Link to comment
https://forums.phpfreaks.com/topic/179305-solved-count/#findComment-946038
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.