PDA

View Full Version : SELECT COUNT issue


sir pannels
02-03-2006, 10:01 AM
hey all,

Got a small problem here. I'm counting rows from a mysql database able and trying to display the count. I have the following.


$count = "SELECT COUNT(*) AS newcount FROM stores";
$cr = mysql_query($count);
if (!$cr)
die(mysql_error());
if($cr){
//Make site ID now ...
$var1 = $newcount;
$var2 = P00;
$var3 = $var2.$var1;
}


The problem I have is thet $newcount seems to be empty. I have used count and not put "AS newcount" in the query but that made no difference. I have tried to echo the $newcount but again it is empty. Now, in PHP is there something else I must do to return the value of $newcount that I have missed?

Many thanks,
Sir P

Rich Pedley
02-03-2006, 12:27 PM
does adding in a WHERE id>0 help?

sir pannels
02-03-2006, 12:57 PM
hey Rich,

Thanks. Though the query actually works fine, if I run the query in MySQL command line I get the count returned to me as newcount.

dumpfi
02-03-2006, 01:43 PM
$count = "SELECT COUNT(*) AS newcount FROM stores";
$cr = mysql_query($count) or die(mysql_error());
//Make site ID now ...
$row = mysql_fetch_assoc($cr);
$var1 = $row['newcount'];
$var2 = P00; // <-- what the hell is this? does this parse?
$var3 = $var2.$var1;
dumpfi

Rich Pedley
02-03-2006, 02:27 PM
doh! I think I totally misread - my bad.

sir pannels
02-03-2006, 04:35 PM
$count = "SELECT COUNT(*) AS newcount FROM stores";
$cr = mysql_query($count) or die(mysql_error());
//Make site ID now ...
$row = mysql_fetch_assoc($cr);
$var1 = $row['newcount'];
$var2 = P00; // <-- what the hell is this? does this parse?
$var3 = $var2.$var1;
dumpfi

thanks dump, that worked great, forgot the grab row business.

That is meant to be = "POO", sorry, lazy. Though yeah it does parse :)

Thanks again,
P