php $count_函数使用方法,高手请解答
问题:我有个数据库:abc表:rco_task我现在要统计task_state里面的0,1,2,3,4,5,6数字的个数!然后显示出来!请问怎么写!task_state里...
问题:
我有个
数据库: abc 表 : rco_task
我现在要统计
task_state
里面的0,1,2,3,4,5,6数字的个数!
然后显示出来!请问怎么写!
task_state里面就是0,1,2,3,4,5,6
我要统计task_state里面的数字出现的次数 展开
我有个
数据库: abc 表 : rco_task
我现在要统计
task_state
里面的0,1,2,3,4,5,6数字的个数!
然后显示出来!请问怎么写!
task_state里面就是0,1,2,3,4,5,6
我要统计task_state里面的数字出现的次数 展开
1个回答
展开全部
task_state是什么东西?
字段数据怎么存放的?
能把需求写详细点么
代码已测,无问题……
<?php
$conn=mysql_connect("localhost","你的用户名","你的密码") or die("无法连接数据库,请重来");
mysql_select_db("abc")
or die("无法选择数据库,请重来");
mysql_query("SET NAMES 'gbk'");//解决汉字
$cishu0=0;$cishu1=0;$cishu2=0;$cishu3=0;$cishu4=0;$cishu5=0;$cishu6=0;
$sql="select task_state from rco_task order by id desc";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_assoc($result))
{
if($row[task_state]==0 and $row[task_state] != "")
{
$cishu0 = $cishu0+1;
}
if($row[task_state]==1)
{
$cishu1 = $cishu1+1;
}
if($row[task_state]==2)
{
$cishu2 = $cishu2+1;
}
if($row[task_state]==3)
{
$cishu3 = $cishu3+1;
}
if($row[task_state]==4)
{
$cishu4 = $cishu4+1;
}
if($row[task_state]==5)
{
$cishu5 = $cishu5+1;
}
if($row[task_state]==6)
{
$cishu6 = $cishu6+1;
}
}
echo "0出现了".$cishu0."次<hr />";
echo "1出现了".$cishu1."次<hr />";
echo "2出现了".$cishu2."次<hr />";
echo "3出现了".$cishu3."次<hr />";
echo "4出现了".$cishu4."次<hr />";
echo "5出现了".$cishu5."次<hr />";
echo "6出现了".$cishu6."次<hr />";
?>
字段数据怎么存放的?
能把需求写详细点么
代码已测,无问题……
<?php
$conn=mysql_connect("localhost","你的用户名","你的密码") or die("无法连接数据库,请重来");
mysql_select_db("abc")
or die("无法选择数据库,请重来");
mysql_query("SET NAMES 'gbk'");//解决汉字
$cishu0=0;$cishu1=0;$cishu2=0;$cishu3=0;$cishu4=0;$cishu5=0;$cishu6=0;
$sql="select task_state from rco_task order by id desc";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_assoc($result))
{
if($row[task_state]==0 and $row[task_state] != "")
{
$cishu0 = $cishu0+1;
}
if($row[task_state]==1)
{
$cishu1 = $cishu1+1;
}
if($row[task_state]==2)
{
$cishu2 = $cishu2+1;
}
if($row[task_state]==3)
{
$cishu3 = $cishu3+1;
}
if($row[task_state]==4)
{
$cishu4 = $cishu4+1;
}
if($row[task_state]==5)
{
$cishu5 = $cishu5+1;
}
if($row[task_state]==6)
{
$cishu6 = $cishu6+1;
}
}
echo "0出现了".$cishu0."次<hr />";
echo "1出现了".$cishu1."次<hr />";
echo "2出现了".$cishu2."次<hr />";
echo "3出现了".$cishu3."次<hr />";
echo "4出现了".$cishu4."次<hr />";
echo "5出现了".$cishu5."次<hr />";
echo "6出现了".$cishu6."次<hr />";
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询