dongyu4863 2016-03-23 16:00
浏览 39

Android,Volley,SQL只显示一条记录?

so after much trouble shooting i have finally gotten my list view working.

Essentially my table has 3 records which should match id 1. I want these to be displayed in my android listview, only 1 is displayed. I assume my php is correct as when i enter myurl://retreiveData.php?id=1

All 3 records are displayed, how ever the android application only displays 1

I will post my php below, and the extract from the java which loops through the json data

 <?php 
 if($_SERVER['REQUEST_METHOD']=='GET'){
   $id  = $_GET['id'];
   require_once('dbConnect.php');
   $sql = "SELECT * FROM Exercises WHERE id='".$id."'";
   $r = mysqli_query($con,$sql);
   while($res = mysqli_fetch_array($r)){
   $result = array();
   array_push($result,array(
   "muscle group"=>$res['muscle group'],
   "exercise"=>$res['exercise'],
  )
  );
   echo json_encode(array("result"=>$result));
  }
   mysqli_close($con);
  }
  • 写回答

1条回答 默认 最新

  • donglu1973 2016-03-23 16:01
    关注

    Move the line $result = array(); above your while loop in PHP.

    On every iteration you are creating a new object. On browser you are able to see because you print the value in each iteration but at the end of the while loop, it will only have the last value. You can test it by echoing the value of $result after the while loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么