在我的網站中,我在很多不同的設置中顯示不同的產品,以確保結果數量正確我想用PHP回顯它們。到目前爲止,我嘗試以我知道的方式迴應他們,但這種方式沒有奏效。迴應SELECT COUNT(*)查詢的結果
我想要回顯的頁面上的代碼包含對頂部的函數文件的require。我曾嘗試:
<?php
//Call the count_stock() function
$result_count = count_stock();
?>
<p>Showing 1-9 of <?php echo $result_count['COUNT(*)']; ?> results.</p>
<p>Showing 1-9 of <?php echo $result_count[0]; ?> results.</p>
<p>Showing 1-9 of <?php print_r($result_count[0]); ?> results.</p>
我執行查詢功能:
//create a function to count get_stock
function count_stock() {
global $conn;
//query the database to count the data entries in the stock table
$sql = 'SELECT COUNT(*) FROM stock';
//use a prepared statement to enhance security
$statement = $conn->prepare($sql);
$statement->execute();
$result_count = $statement->fetchAll();
$statement->closeCursor();
return $result_count;
}
什麼var_dump($ result_count)返回? –