首页 > 代码库 > php输出mysqli查询出来的结果
php输出mysqli查询出来的结果
php连接mysql我有文章已经写过了,这篇文章主要是介绍从mysql中查询出结果之后怎么输出的问题。
一:mysqli_fetch_row();
查询结果:array([0]=>小王)
查询:
[php] view plain copy
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[0];
- }//end while()
二:mysqli_fetch_assos();
查询结果:array([name]=>小王)
查询:
[php] view plain copy
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[‘memberlist‘];
- }//end while()
三、mysqli_fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
[php] view plain copy
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[‘memberlist‘];
- $memberlist = $row[0];
- }//end while()
四、fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
[php] view plain copy
- $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()即使用数字也使用关键字做索引。
php输出mysqli查询出来的结果
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。