2016-05-02 42 views
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"}]} 

回答

0

參考這個知道h OW從Android將數據發送到服務器 http://kb4dev.com/article/how-to-connect-android-with-php-mysql-and-json

,並從SharedPreference發送數據時,使用該

String s_id = ui.getString("s_id","s_id"); 
new SignupActivity(this).execute(s_id); 

以及從JSON獲取值,請參閱本

http://www.kaleidosblog.com/android-listview-load-data-from-json

如果您仍然有任何懷疑,問,我會幫助。快樂編碼!

+0

高興地幫助你。 –

相關問題