sql - PHP query record number problem, count exception
大家讲道理
大家讲道理 2017-05-16 13:16:02
0
3
496
    mysql_select_db("zaiping", $con);
    $result = array();
    $rs = mysql_query("select count(*) as count from dept where deptName like $deptName");
    $row = mysql_fetch_array($rs);
    ChromePhp::log($row);
    $result["total"] = $row[0];

sql command line executionselect count(*) as count from dept where deptName like $deptName is no problem. It is also no problem if the number of records >=2. The problem is that when there is 1 When matching data, $result["total"]=0, why is this, why is it not 1? Thanks

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
给我你的怀抱
你把$row[0]改成$row[0]['count']试试;显示过滤了
阿神

$rs = mysql_query("select count(*) as count from dept where deptName like '%".$deptName."%'");
SQL like 请加百分号

大家讲道理

When this kind of problem occurs, I usually solve it like this:

$sql = "select count(*) as count from dept where deptName like $deptName";
print_r($sql);        //将输出的SQL拿到MySQL去执行,看报什么错误
$re = mysql_query($sql);
var_dump($re);        //查看返回什么

Based on the output, make corresponding judgments to see where the problem lies.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template