|
|
|
Android - มีปัญหาอยู่ว่า ทำไม่ กด selete แล้วมันไม่ show ในหน้าหลักอ่าครับ |
|
|
|
|
|
|
|
Code (Android-Java)
public void select() { //------------ Method to select data ---------------//
tv_res.setText("");
InputStream is = null;
String js_result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://127.0.0.1:80/php_get_data.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Toast.makeText(getApplicationContext(), "yse !!! ",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.d("log_err", "Error in http connection " + e.toString());
Toast.makeText(getApplicationContext(), "No selete",Toast.LENGTH_SHORT).show();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf8_bin"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
js_result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
final JSONArray jArray = new JSONArray(js_result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jo = jArray.getJSONObject(i);
String hn = jo.getString("hn");
String name = jo.getString("name");
String age = String.valueOf(jo.getInt("age"));
String date_serv = jo.getString("date_serv");
Log.d("log",hn+","+name+","+age+","+date_serv);
tv_res.append(hn+","+name+","+age+","+date_serv+"\n");
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
Toast.makeText(getApplicationContext(), "No show ",Toast.LENGTH_SHORT).show();
}
}
อันนี้ code php การ Connetion ไฟล์ ชื่อ php_get_data.php ครับ
Code (PHP)
<?php
header("content-type:text/javascript;charset=utf-8");
$con=mysql_connect('127.0.0.1','root','1234')or die(mysql_error()); // เปลี่ยน localhost เป็น ip ของ mysql server
mysql_select_db('android')or die(mysql_error());
mysql_query("SET NAMES UTF8");
$sql="SELECT * FROM patient";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){
$output[]=$row;
}
print(json_encode($output));
mysql_close();
?>
Tag : Mobile, MySQL, Ms SQL Server 2005, CakePHP, Android
|
|
|
|
|
|
Date :
2014-08-10 18:50:01 |
By :
heloman |
View :
1143 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug ดูเลยครับ ว่ามันหลุดตรงไหน หรือมี LogCat Error ไหม๊ครับ
|
|
|
|
|
Date :
2014-08-11 16:55:41 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|