我将派出数组到Java为了填充一个ListView,我怎么得到下面的代码输出数组?:在PHP中使用
<?php
$user = 'root';
$pass = '';
$db = 'uopuser';
$con=mysqli_connect('localhost', $user, $pass, $db) or die('Unable to connect');
$statement = mysqli_prepare($con, 'SELECT * FROM society');
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $society_id, $name, $email, $description);
$society = array();
while(mysqli_stmt_fetch($statement)){
$society['society_id'] = $society_id;
$society['name'] = $name;
$society['email'] = $email;
$society['description'] = $description;
echo json_encode($society);
}
echo json_encode($society);
mysqli_stmt_close($statement);
mysqli_close($con);
?>
而不是:
{"society_id":1,"name":"TestName1","email":"[email protected]","description":"TestDes1"}
{"society_id":2,"name":"TestName2","email":"[email protected]","description":"TestDes2"}
{"society_id":3,"name":"TestName3","email":"[email protected]","description":"TestDes3"}
我发表了这篇文章之前看过有关互联网,但我很困惑!感谢任何人提前。
你可以这样做:$ societies = array(); $ societies.push($社会);回声json_encode($社会); 将$社会推送到循环内部的$ societies数组中,并在此循环之外进行编码。 –