Note that there are some explanatory texts on larger screens.

plurals
  1. POData from a MySQL database is not displaying in Android Textview
    primarykey
    data
    text
    <p>I can't display data from a MySQL database. I want to retrieve some data from my database and display it to the textview, but it's not working.</p> <p>Java code:</p> <pre><code>public class Penjualan1 extends Activity { // All xml labels String pid; TextView mejaTv; TextView customerTv; TextView keteranganTv; // Progress Dialog private ProgressDialog pDialog; // Creating JSON Parser object JSONParser jsonParser = new JSONParser(); // Profile JSON url private static final String url_order_detials = "-my url-/get_penjualan_details.php"; // ALL JSON node names private static final String TAG_PRODUCT = "product"; private static final String TAG_SUCCESS = "success"; private static final String TAG_GET = "get"; private static final String TAG_MEJA = "meja"; private static final String TAG_CUST = "customer"; private static final String TAG_KET = "keterangan"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.f_penjualan1); mejaTv = (TextView) findViewById(R.id.meja); customerTv = (TextView) findViewById(R.id.customer); keteranganTv = (TextView) findViewById(R.id.keterangan); // Loading Profile in Background Thread new GetProductDetails().execute(); } /** * Background Async Task to Get complete product details * */ class GetProductDetails extends AsyncTask&lt;String, String, String&gt; { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(Penjualan1.this); pDialog.setMessage("Loading product details. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } /** * Getting product details in background thread * */ protected String doInBackground(String... params) { // updating UI from Background Thread runOnUiThread(new Runnable() { public void run() { // Check for success tag // TODO Auto-generated method stub int success; try { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("pid", pid)); // getting product details by making HTTP request // Note that product details url will use GET request JSONObject json = jsonParser.makeHttpRequest( url_order_detials, "GET", params); // check your log for json response Log.d("Single Product Details", json.toString()); // json success tag success = json.getInt(TAG_SUCCESS); if (success == 1) { // successfully received product details JSONArray productObj = json .getJSONArray(TAG_GET); // JSON Array // get first product object from JSON Array JSONObject product = productObj.getJSONObject(0); // product with this pid found // Edit Text mejaTv = (TextView) findViewById(R.id.meja); customerTv = (TextView) findViewById(R.id.customer); keteranganTv = (TextView) findViewById(R.id.keterangan); // display product data in EditText mejaTv.setText(product.getString(TAG_MEJA)); customerTv.setText(product.getString(TAG_CUST)); keteranganTv.setText(product.getString(TAG_KET)); }else{ // product with pid not found } } catch (JSONException e) { e.printStackTrace(); } } }); return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // dismiss the dialog once got all details pDialog.dismiss(); } } } </code></pre> <p>PHP Code: <code></p> <pre><code>/* * Following code will get single product details * A product is identified by product id (pid) */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $db = new DB_CONNECT(); // check for post data if (isset($_GET["pid"])) { $pid = $_GET['pid']; // get a product from products table $result = mysql_query("SELECT *FROM penjualan WHERE pid = $pid"); if (!empty($result)) { // check for empty result if (mysql_num_rows($result) &gt; 0) { $result = mysql_fetch_array($result); $product = array(); $product["pid"] = $result["pid"]; $product["meja"] = $result["meja"]; $product["customer"] = $result["customer"]; $product["keterangan"] = $result["keterangan"]; // success $response["success"] = 1; // user node $response["get"] = array(); array_push($response["get"], $product); // echoing JSON response echo json_encode($response); } else { // no product found $response["success"] = 0; $response["message"] = "No product found"; // echo no users JSON echo json_encode($response); } } else { // no product found $response["success"] = 0; $response["message"] = "No product found"; // echo no users JSON echo json_encode($response); } } else { // required field is missing $response["success"] = 0; $response["message"] = "Required field(s) is missing"; // echoing JSON response echo json_encode($response); } ?&gt; </code></pre> <p></code></p> <p>I've seen sample code from other posts, but I don't quite understand how to apply it. Can you please give me sample code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload