简体   繁体   中英

how display mysql query count(*) result in textview android using php page

我正在使用一个查询在mysql数据库中使用count( 在表中输出总记录。我想显示count( )结果使用php页面在应用程序中检索数据到textview。

For fetching data from MySQL database, you have to create a Web API which helps you to fetch data and display in Android. You have to implement JSON Parsing logic before displaying actual data into TextView.

Can you try this, select count(*) as total from tablename

  1. you can retruve the total value from php and returned as json format.

  2. In android, you can parse the json resposne from web API, and set in android textview.

Example: Android code

JSONObject jObject;
jObject = new JSONObject(data);
String total = jObject.getString("total");
myView.setText(total);
Cursor cur = mDb.rawQuery(" SELECT Count(*) FROM  Tasks ", null);
int x = 0;
if (cur.moveToFirst())
{
    x = cur.getInt(0);
}
cur.close();
return x;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM