亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從模型代碼點火器中獲取不同的結果數組

從模型代碼點火器中獲取不同的結果數組

PHP
神不在的星期二 2022-12-23 15:12:55
    我是使用 Codeigniter 作為 web api 的新手,我想得到這個結果{"result":[{"id":"1","nama":"Orion","nomor":"08576666762"},{"id":"2","nama":"Mars","nomor":"08576666770"},{"id":"7","nama":"Alpha","nomor":"08576666765"}],"success":"1","message":"success"} 但我得到了這種結果:{"result":[[{"id":"1","nama":"Orion","nomor":"08576666762"},{"id":"2","nama":"Mars","nomor":"08576666770"},{"id":"7","nama":"Alpha","nomor":"08576666765"}]],"success":"1","message":"success"}我想知道我哪里弄錯了?我正在使用 codeigniter,下面的代碼來自控制器和模型m_server.php(模式)<?php     Class M_server extends CI_Model {        function __construct(){            parent::__construct();            $this->load->database();        }        // buat view dashboard main        function dash_main1(){            $data = $this->db->query("            select *            from telepon            ");            $result = array();            $result['result'] = array();            $result['success'] = "1";            $result['message'] = "success";            array_push($result['result'], $data->result());            return $result;        }    }Rest_server.php(控制器)<?phpdefined('BASEPATH') OR exit('No direct script access allowed');class Rest_server extends CI_Controller {    function __construct(){        parent::__construct();        $this->load->model('m_server');    }    public function index()    {        $this->load->helper('url');        $this->load->view('rest_server');    }    function dash_main1(){        $data=$this->m_server->dash_main1();        echo json_encode($data);    }}
查看完整描述

1 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

刪除此行(可選)

$result['result'] = array();

并改變這一行

$result['result'] = $data->result(); //result become the array

array_push向現有數組添加元素


查看完整回答
反對 回復 2022-12-23
  • 1 回答
  • 0 關注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號