zoukankan      html  css  js  c++  java
  • php 用mysqli的json_encode()转换出来 全是对象的问题

    <?php
    /**
     * Created by PhpStorm.
     * User: Administrator
     * Date: 2018/9/6 0006
     * Time: 15:33
     */
    //查询所有用户
    error_reporting(E_ALL ^ E_DEPRECATED);
    $link=new mysqli('localhost','root','root','pho');
    
    if($link->connect_errno){
        die($link->connect_errno);
    }
    
    /*分页
    要知道 $size 自己定义显示几行
    $length 总行数
    $start 开始页码*/
    
    $size=3;
    $start=$_POST['num']-1;
    $startpage=3*$start;
    
    $sql="select id,name from admin_biao limit $startpage,$size";
    $res=$link->query($sql);
    
    $array=array();
    $inum=0;
    while ($row=$res->fetch_assoc()){
        $array[$inum]=$row;
        $inum++;
    }
    
    $data=array();
    $data['cont']=$array;
    
    $data=json_encode($data);
    header('content-type:application/json');
    echo $data;
    ?>

    因为  在$inum 如果在while里面  先执行了++;就会返回的json全是对象、

    如果把++在最后执行,就该是数组的还是数组。

  • 相关阅读:
    Wireshark——工具
    Wireshark——网络协议
    Wireshark——过滤器
    Wireshark——数据包、着色规则和提示
    Floyd最小环
    有向环覆盖问题
    KM算法
    归并排序
    树状数组
    构造强连通图
  • 原文地址:https://www.cnblogs.com/gaidalou/p/9603421.html
Copyright © 2011-2022 走看看