我有 1000 多条记录。我必须为每个请求提供 50 条记录,例如 0-50、50-100、100-150 像这样。我正在使用以下代码:
public function get_database($data)
<?php
{
$start = $data['start'];
$limit = $data['limit'];
$alumni_details = array();
$query1 = "select * from alumni where
status='Active',limit '".$start."','".$limit."' ";
$query_run = mysql_query($query1);
while($row = mysql_fetch_assoc($query_run))
{
$row['date_of_birth'] = date('d M, Y', strtotime($row['date_of_birth']));
$alumni_detail['alumni_details'] = $row;
$alumni_details[] = $alumni_detail;
}
echo json_encode($alumni_details);
}
但我只需要取 user_id,因为我需要在 json 中动态编码数据,但有限制。
最佳答案
您的代码如下:
$start = $data['start'];
$query = SELECT * FROM `alumni` WHERE `status` = 'Active' ORDER BY `alumni_id` LIMIT $start,5"
它应该是动态的 5 不会被当作常量。把它放在一些变量中, 是的,它应该是固定的,但根据 future 的要求,它可以改变,所以把它放在变量中。
关于php - 使用 php 为移动应用程序(如 android、ios)动态编码 json 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24752133/