任何人都可以幫助我做到這一點。我試圖從表中獲取所有數據。但它仍然以布爾值的形式返回。爲什麼說布爾被賦予
<?php
$con = mysqli_connect("localhost", "root", "", "student");
$query = "SELECT * FROM `announcement` ORDER BY `announce_id` DESC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
echo json_encode($data);
?>
給出的錯誤是:
> Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result,
> boolean given in D:\Xampp\htdocs\student\announcement.php on line 8
>
> Notice: Undefined variable: data in
> D:\Xampp\htdocs\student\announcement.php on line 12 null
總是檢查錯誤'($ con,$ query)或死($ con>錯誤)' – Ghost
您的查詢失敗,它返回布爾值false – nogad
[mysqli \ _fetch \ _array()/ mysqli \ _fetch \ _assoc()/ mysqli \ _fetch \ _row()期望參數1是資源或mysqli \ _result,布爾給定](http://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc -mysqli-fetch-row-expects-parameter-1) –