php連接配接mysql我有文章已經寫過了,這篇文章主要是介紹從mysql中查詢出結果之後怎麼輸出的問題。
一:mysqli_fetch_row();
查詢結果:array([0]=>小王)
查詢:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row[0];
}//end while()
二:mysqli_fetch_assos();
查詢結果:array([name]=>小王)
$memberlist = $row['memberlist'];
三、mysqli_fetch_array();
查詢結果:array([0]=>小王 [name]=>小王)
四、fetch_array();

$sql = "select * from user";
$result = $conn->query($sql);
if ($result)
{
if ($result->num_rows>0)
{
while ($rows = $result->fetch_array()) {
print_r($rows);
echo "<BR>rows['id']:".$rows['id'];
echo "<BR>rows['name']:".$rows['name'];
echo "<BR>rows['pwd']:".$rows['pwd'];
}//end while()
}else{
echo "<BR>查詢結果為空!";
}//end if()
}else{
echo "<BR>查詢失敗!";
}//end if()
從上面可以看出不同的函數輸出的格式也是不一樣的,mysqli_fetch_row()傳回的是以數字做索引的,mysqli_fetch_assos()是以關鍵字做索引的,而mysqli_fetch_array()和fetch_array()即使用數字也使用關鍵字做索引。