我正在尝试将mysql值存储到php变量中。我有以下查询,据我所知。但是,我$ count的值始终为0。有人可以解释我需要做些什么来获取计数值吗?该计数应为x的计数w,此处name_x =。$ id。
$query = "SELECT COUNT(name_x) FROM Status where name_x=.$id.";
$result = mysql_query($query);
$count = $result;
最佳答案
表名中的第一个字母真的是大写。请先检查一下。
或尝试:
$query = "SELECT COUNT(*) as totalno FROM Status where name_x=".$id;
$result = mysql_query($query);
while($data=mysql_fetch_array($result)){
$count = $data['totalno'];
}
echo $count;
关于php - 选择计数php/sql,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9543655/