tags:

views:

12

answers:

2

Hello,

For the query below, I would like to set a variable called $totalcount equal to the count of all loginids in table called login. How can I do this?

Thanks in advance,

John

$sqlStrcount = "SELECT loginid FROM login";
+1  A: 
$sqlQueryStr = "SELECT loginid FROM login";
$sqlQuery = mysql_query($sqlQueryStr);

$totalCount = mysql_num_rows($sqlQuery);

If you only need to count your records in login use this instead for performance reasons.

$sqlQueryStr = "SELECT COUNT(loginid) as totalCount FROM login";
$sqlQuery = mysql_query($sqlQueryStr);

$row = mysql_fetch_assoc($sqlQuery);
$totalCount = $row['totalCount'];
madsleejensen
A: 

If you only need the count:

"select count(loginid) as c from login"
bazmegakapa