私のクエリが次の場合、これが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"];
このようにしてみてください:
<?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_* 関数は非推奨です。これらの関数の使用は避けてください。
ちなみに、そのコードをこのように書くことができます...
$query = "
SELECT COUNT(*) call_count
FROM callsepaug
WHERE start_time BETWEEN '$start_date' AND '$end_date';
";