当我的查询如下时,如果这在 php 中,我如何获得结果:
$query = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
$query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
$query .= "'" . $end_date . "'";
这和一个简单的查询一样,你可以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"];
顺便说一句,你可以这样写代码......
$query = "
SELECT COUNT(*) call_count
FROM callsepaug
WHERE start_time BETWEEN '$start_date' AND '$end_date';
";
尝试这个:
$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];
试试这样:
<?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_* 函数。避免使用这些功能。