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()
查询结果:array([0]=>小王 [name]=>小王)
查询:
while ($row = mysqli_fetch_assoc($result)) { $memberlist = $row['memberlist']; $memberlist = $row[0]; }//end while()
四、fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
$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()即使用数字也使用关键字做索引。
原文地址:http://blog.csdn.net/leedaning/article/details/46236727