PHP json_encode() in while loop

后端 未结 3 1706
花落未央
花落未央 2021-01-01 07:53

I am trying to use json_encode() in a while loop while getting database results. Here is my code:



        
3条回答
  •  被撕碎了的回忆
    2021-01-01 08:34

    Change this

    while($row = sqlite_fetch_array($results)) {
      $data = $row['uid'] . " " . $row['username'] . " " . $row['xPos'] . " " . $row['yPos'];
    }
    

    to

    $data = array();
    while($row = sqlite_fetch_array($results)) {
      $data[] = $row['uid'] . " " . $row['username'] . " " . $row['xPos'] . " " . $row['yPos'];
    }
    

提交回复
热议问题