如果我的查询如下,我怎样才能得到结果:
$query = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$query .= "'" . $end_date . "'";
答案 0 :(得分:1)
与简单查询相同,您get count(*)
可以call_count
$queryBuild = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$queryBuild .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$queryBuild .= "'" . $end_date . "'");
$query = mysqli_query($queryBuild);
$result = mysqli_fetch_array($query);
echo $result['call_count'];
或使用对象
$query = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$query .= "'" . $end_date . "'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo $row["call_count"];
答案 1 :(得分:0)
试试这样:
<?php
$query = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$query .= "'" . $end_date . "'";
$result = $mysqli->query($query);
$row_array=$result->fetch_array(MYSQLI_ASSOC);
print($row_array['TOTALFOUND']);
注意:不推荐使用Mysql_ *函数。避免使用这些功能。
答案 2 :(得分:0)
顺便说一下,你可以用这种方式编写代码......
$query = "
SELECT COUNT(*) call_count
FROM callsepaug
WHERE start_time BETWEEN '$start_date' AND '$end_date';
";
答案 3 :(得分:0)
试试这个:
$query = mysql_query("SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$query .= "'" . $end_date . "'");
$result = mysql_fetch_array($query);
echo $result[0];