php輸出mysqli查詢出來的結果

來源:互聯網
上載者:User
php串連mysql我有文章已經寫過了,這篇文章主要是介紹從mysql中查詢出結果之後怎麼輸出的問題。
一:mysqli_fetch_row();
查詢結果:array([0]=>小王)
查詢:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row[0];
}//end while()

二:mysqli_fetch_assos();
查詢結果:array([name]=>小王)
查詢:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row['memberlist'];
}//end while()

三、mysqli_fetch_array();
查詢結果:array([0]=>小王 [name]=>小王)
查詢:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row['memberlist'];
$memberlist = $row[0];
}//end while()

四、fetch_array();
查詢結果:array([0]=>小王 [name]=>小王)
查詢:` sql=“select?fromuser”; result = conn?>query( sql);

if (result)
{
if (result->num_rows>0)
{
while ( rows= result->fetch_array()) {
print_r( rows);echo“rows[‘id′]:”. rows[‘id’];
echo “
rows[‘name’]:”. rows[‘name′];echo“rows[‘pwd′]:”. rows[‘pwd’];
}//end while()
}else{
echo “
查詢結果為空白!”;
}//end if()
}else{
echo “
查詢失敗!”;
}//end if() `

從上面可以看出不同的函數輸出的格式也是不一樣的,mysqli_fetch_row()返回的是以數字做索引的,mysqli_fetch_assos()是以關鍵字做索引的,而mysqli_fetch_array()和fetch_array()即使用數字也使用關鍵字做索引。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.