我是使用 API 的新手。我在计算数据并将其显示到 html 视图时遇到问题。我正在使用 count($data) 在 html 视图中对其进行计数,但如果将其与数据进行比较,结果会有所不同。这是我从 API 获得的数据。我这里只显示 9 个样本数据。这是我从 API 获得的数据。
{"rows":[{"ID":26,"Name":"Design Request (Draft)"},
{"ID":25,"Name":"Kirim Produk Iklan"},
{"ID":27,"Name":"Kirim Produk Iklan Reguler"},
{"ID":18,"Name":"KMP - Advertorial"},
{"ID":34,"Name":"KMP - Advertorial Daerah"},
{"ID":5,"Name":"KMP - Artikel"},
{"ID":9,"Name":"KMP - Artikel Editor"},
{"ID":28,"Name":"KMP - Artikel PB"},
{"ID":29,"Name":"KMP - Desain Grafis"},
"status":0,"message":"","messagedescription":"","rowcount":9,"columns":["ID","Name"]}
这是我的控制器
function index(){
$output = $this->http_request('http://api.com');
$profile = json_decode($output, TRUE);
$config['total_rows'] = count($profile);
var_dump($config);
$data['data']=$profile;
$data['sidebar']='sidebar';
$data['content']='apinew';
$this->load->view('main',$data);
}
function http_request($url){
// persiapkan curl
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
// set user agent
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// tutup curl
curl_close($ch);
// mengembalikan hasil curl
return $output;
}
这是我的观点
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center" scope="col"> ID </th>
<th class="text-center" scope="col">Job</th>
<th class="text-center" scope="col">Action</th><!--
<th class="text-center">Actions</th> -->
</tr>
</thead>
<tbody>
<?php for($i =0 ; $i < count($data); $i++){ ?>
<tr>
谢谢你 :)
LEATH