开发者

Setting variable equal to count of a field in database table

开发者 https://www.devze.com 2023-01-20 13:53 出处:网络
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 th开发者_开发技巧is?

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 th开发者_开发技巧is?

Thanks in advance,

John

$sqlStrcount = "SELECT loginid FROM login";


$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'];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号