本文介紹了mysqli_fetch_array 只返回一個結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試使用以下代碼(在 $host 中使用適當的值等)對小型 mysql 數據庫進行非常非常簡單的查詢:
I'm trying to make a very, very simple query of a small mysql database, using the following code (with appropriate values in $host, etc.):
$result = mysqli_query($connection, "select university from universities_alpha");
$row = mysqli_fetch_array($result);
echo print_r($result);
echo '<br><br>';
echo print_r($row);
如您所見,我以人類可讀的方式打印了結果,結果是:
As you can see, I printed out the results in a human-readable way, yielding:
mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => Array ( [0] => 19 ) [num_rows] => 9 [type] => 0 ) 1
Array ( [0] => Arizona State Univ. [university] => Arizona State Univ. ) 1
該專欄中有一些示例大學,所以我不確定我做錯了什么.
There are a few example universities in that column, so I'm not sure what I'm doing wrong.
推薦答案
mysqli_fetch_array 每次調用時都通過指針工作
mysqli_fetch_array works by pointers each time it's called
想象以下內容
$result = mysqli_query($connection, "select university from universities_alpha");
$row = mysqli_fetch_array($result); // this is the first row
$row = mysqli_fetch_array($result); // now it's the second row
$row = mysqli_fetch_array($result); // third row
要以您想要的方式實際顯示數據,我建議您執(zhí)行以下操作
To actually display the data the way you want it to, I suggest you do the following
$rows = array();
$result = mysqli_query($connection, "select university from universities_alpha");
while($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}
print_r($rows);
這篇關于mysqli_fetch_array 只返回一個結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!