简体   繁体   中英

How to get total data table from database mysql and display in android

I want to show my total data table from database mysql to android, such as I have table road with 5 data inside the table, then display in android textview like this "your data: 5", please help me because my textview cannot display anything, this is mycode

try {
        JSONArray data_belum = new JSONArray(getJSONUrl(urlDataBelum));

        for (int i = 0; i < data_belum.length(); i++) {
            try {
                JSONObject c = data_belum.getJSONObject(i);
                int userId = Integer.parseInt(c.getString("status"));
                belum.setText(userId);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

then it's my php code

$result = mysql_query("SELECT * FROM laporan WHERE status = 'belum diperbaiki'");
$num_rows = mysql_num_rows($result);
$output = array($num_rows);
echo json_encode($output);

This is refering to an ID in R.string.*

belum.setText(userId);

To display an Integer use String.valueOf() instead:

belum.setText(String.valueOf(userId));

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