php 显示mysql计数功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3794066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:08:50 来源:igfitidea点击:
display the mysql count function?
提问by getaway
$query = "select count(*)
from relationships
where leader = 'user_id'";
$result = mysql_query($query);
how can i display the count? thanks
我怎样才能显示计数?谢谢
回答by Mischa
$count = mysql_fetch_array($result);
echo $count[0];
回答by sushil bharwani
$query = "SELECT COUNT(*) AS total FROM table"; $result = mysql_query($query); $values = mysql_fetch_assoc($result); $num_rows = $values['total']; echo $num_rows;
回答by hacksteak25
- use
$row = mysql_fetch_array($result)
and access it by index 0: $row[0] - use an alias in your query ("select count(*) as cnt from ...") and
$row = mysql_fetch_assoc($result)
and access it by name: $row['cnt']
$row = mysql_fetch_array($result)
通过索引 0使用和访问它:$row[0]- 在您的查询中使用别名(“select count(*) as cnt from ...”)并按
$row = mysql_fetch_assoc($result)
名称访问它: $row['cnt']
回答by Pushkar Pokharkar
$abc="SELECT count(*) as c FROM output WHERE question1=4";
$result=mysqli_query($conn,$abc);
if($result)
{
while($row=mysqli_fetch_assoc($result))
{
echo $row['c'];
}
}
Its work completely in this it count the number of occurrences of 4 in the column
它的工作完全在此它计算列中 4 的出现次数