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

このようにしてみてください:

<?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 に答える
0

ちなみに、そのコードをこのように書くことができます...

$query = "
SELECT COUNT(*) call_count 
  FROM callsepaug
 WHERE start_time BETWEEN '$start_date' AND '$end_date';
 ";
于 2013-10-28T10:49:07.627 に答える