zoukankan      html  css  js  c++  java
  • php输出mysqli查询出来的结果

    php连接mysql我有文章已经写过了,这篇文章主要是介绍从mysql中查询出结果之后怎么输出的问题。 
    一:mysqli_fetch_row(); 
    查询结果:array([0]=>小王) 
    查询:

    [php] view plain copy
     
    1. while ($row = mysqli_fetch_assoc($result)) {   
    2. $memberlist = $row[0];   
    3. }//end while()  

    二:mysqli_fetch_assos(); 

    查询结果:array([name]=>小王) 
    查询:

    [php] view plain copy
     
    1. while ($row = mysqli_fetch_assoc($result)) {   
    2. $memberlist = $row['memberlist'];   
    3. }//end while()  


    三、mysqli_fetch_array(); 

    查询结果:array([0]=>小王 [name]=>小王) 
    查询:

    [php] view plain copy
     
    1. while ($row = mysqli_fetch_assoc($result)) {   
    2. $memberlist = $row['memberlist'];   
    3. $memberlist = $row[0];   
    4. }//end while()  

    四、fetch_array(); 
    查询结果:array([0]=>小王 [name]=>小王) 
    查询:

    [php] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. $sql = "select * from user";    
    2. $result = $conn->query($sql);    
    3.     
    4. if ($result)     
    5. {    
    6.     if ($result->num_rows>0)    
    7.     {    
    8.         while ($rows = $result->fetch_array()) {    
    9.             print_r($rows);    
    10.             echo "<BR>rows['id']:".$rows['id'];    
    11.             echo "<BR>rows['name']:".$rows['name'];    
    12.             echo "<BR>rows['pwd']:".$rows['pwd'];    
    13.         }//end while()    
    14.     }else{    
    15.         echo "<BR>查询结果为空!";       
    16.     }//end if()    
    17. }else{    
    18.     echo "<BR>查询失败!";     
    19. }//end if()    

    从上面可以看出不同的函数输出的格式也是不一样的,mysqli_fetch_row()返回的是以数字做索引的,mysqli_fetch_assos()是以关键字做索引的,而mysqli_fetch_array()和fetch_array()即使用数字也使用关键字做索引。

  • 相关阅读:
    frame和iframe区别
    idea基本
    Spring中加载xml配置文件的六种方式
    java中Map,List与Set的区别
    java集合框架
    springmvc IDEA
    springmvc 精华
    eclipse 中 git 解决冲突(重点)
    启动Tomcat报错 java.util.zip.ZipException: invalid LOC header (bad signature)
    PowerDesigner 提示 Existence of index、key、reference错误
  • 原文地址:https://www.cnblogs.com/soundcode/p/6928961.html
Copyright © 2011-2022 走看看