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
阿神2017-05-16 13:18:02
$rs = mysql_query("select count(*) as count from dept where deptName like '%".$deptName."%'");
SQL like 请加百分号
大家讲道理2017-05-16 13:18:02
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.