0

当我的查询如下时,如果这在 php 中,我如何获得结果:

$query = "SELECT COUNT(*) AS call_count FROM `callsepaug` ";
        $query .= "WHERE start_time BETWEEN '" . $start_date . "' AND ";
        $query .= "'" . $end_date . "'";
4

4 回答 4

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"];
于 2013-10-28T10:42:57.660 回答
0

顺便说一句,你可以这样写代码......

$query = "
SELECT COUNT(*) call_count 
  FROM callsepaug
 WHERE start_time BETWEEN '$start_date' AND '$end_date';
 ";
于 2013-10-28T10:49:07.627 回答
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];
于 2013-10-28T12:01:38.527 回答
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_* 函数。避免使用这些功能。

于 2013-10-28T10:43:39.567 回答