 |
Android ต้องการเพิ่มตัวแปรเพื่อใช้สำหรับนับจำนวนแถวในฐานข้อมูล (php กับ mysql) ทำอย่างไรครับ |
|
 |
|
|
 |
 |
|
นับจาก json ได้เลยครับ
Code (Android-Java)
String json = "{\"sName\":\"Sawatdee : Weerachai Nukitram\",\"sEmail\":\"Sawatdee : [email protected]\"}";
JSONObject c = new JSONObject(json);
// c.count;
// c.length;
|
 |
 |
 |
 |
Date :
2013-05-18 08:08:28 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าจากโค๊ดตรงนี้ เพิ่มอย่างไรครับ ขอบคุณครับ
Code
try {
JSONArray data = new JSONArray(getJSONUrl(url,params));
MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("member_id", c.getString("member_id"));
map.put("date", c.getString("date"));
MyArrList.add(map);
}
|
 |
 |
 |
 |
Date :
2013-05-18 08:21:20 |
By :
apivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อยากให้แสดงครั้งที่ 1... 2 ...3....แบบนี้ครับ

|
 |
 |
 |
 |
Date :
2013-05-18 08:28:13 |
By :
apivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ สำเร็จแล้ว แจ่มเลย..
Code
for(int i = 0; i < data.length(); i++){
int num = 1;
num += i ;
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("member_id", c.getString("member_id"));
map.put("date", c.getString("date"));
map.put("num", String.valueOf(num));
MyArrList.add(map);
|
 |
 |
 |
 |
Date :
2013-05-18 12:21:35 |
By :
apivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-05-18 13:41:25 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|