1
我想顯示數據從MySQL到列表視圖。如何從SharedPreferences向PHP腳本發送數據並在listview中顯示JSON?
這裏是我的PHP腳本:
home.php S_ID =
<?php
$con= new mysqli("localhost","root","","studentbuzz");
$user_id = $_GET['s_id'];
$res=mysqli_query($con,"SELECT class.c_id,class.c_name,class.c_desc FROM student_class INNER JOIN class ON class.c_id=student_class.c_id WHERE s_id='$user_id'");
$response = array();
while($row = mysqli_fetch_array($res))
{
$response[] = array("c_id"=>$row[0],"c_name"=>$row[1],"c_desc"=>$row[2]);
}
echo json_encode(array("class"=>$response));
mysqli_close($con);
?>
這裏是我的SharedPreferences數據:
SharedPreferences ui = this.getSharedPreferences("UserInfo", Context.MODE_PRIVATE);
String s_id = ui.getString("s_id","s_id");
JSON輸出:
{"class":[{"c_id":"12","c_name":"Java","c_desc":"Learn Java"}, {"c_id":"13","c_name":"ggg","c_desc":"ffff"}]}
高興地幫助你。 –