php - 使用 php 为移动应用程序(如 android、ios)动态编码 json 中的数据

标签 php mysql json

我有 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/

相关文章:

php - 如何使用变量更新mysql数据库?

json - 在 Swift 中保存 http 请求的响应

php - CLink 列和过滤器

php - 将目标属性添加到 html 链接

python - 处理 PyMySql 异常 - 最佳实践

mysql - 为什么数学运算符与sql中的字符串交互

php - 将单独查询的结果添加到 JSON 编码数组

java - 如何从这个 JSONString 解析?

php - 检查数据库的权限,如果找不到则重定向

mysql - 如何在MySQL中找到计数结果的平均值?