I want to display data from MySQL to listview.
Here is my PHP script:
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);
?>
Here is my SharedPreferences data:
SharedPreferences ui = this.getSharedPreferences("UserInfo", Context.MODE_PRIVATE);
String s_id = ui.getString("s_id","s_id");
JSON output:
{"class":[{"c_id":"12","c_name":"Java","c_desc":"Learn Java"}, {"c_id":"13","c_name":"ggg","c_desc":"ffff"}]}
Refer this to know how to send data from android to server http://kb4dev.com/article/how-to-connect-android-with-php-mysql-and-json
and to send data from SharedPreference, use this
String s_id = ui.getString("s_id","s_id");
new SignupActivity(this).execute(s_id);
And for getting values from JSON, refer this
http://www.kaleidosblog.com/android-listview-load-data-from-json
If you still have any doubts, ask and I will help. Happy Coding!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.