daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $host='localhost';
  3. $user='root';
  4. $password='';
  5. $db='employee101';
  6. $_id = $_POST['id'];
  7.  
  8. $sql = "select * from employee_comments where id = $_id;";
  9.  
  10. $con = mysqli_connect($host,$user,$password,$db);
  11.  
  12. $result = mysqli_query($con, $sql);
  13.  
  14. $response = array();
  15.  
  16. while($row = mysqli_fetch_array($result)){
  17.  
  18.     array_push($response,array("id"=>$row[0],"comment"=>$row[1],"rating"=>$row[2]));
  19.  
  20. }
  21.  
  22. echo json_encode(array("server_respo"=>$response));
  23.  
  24. mysqli_close($con);
  25.  
  26.  
  27.  
  28.  
  29. ?>
  30.    
  31. import android.content.Intent;
  32. import android.os.AsyncTask;
  33. import android.support.v7.app.AppCompatActivity;
  34. import android.os.Bundle;
  35. import android.view.View;
  36. import android.widget.ArrayAdapter;
  37. import android.widget.EditText;
  38. import android.widget.ListView;
  39. import android.widget.TextView;
  40. import android.widget.Toast;
  41.  
  42. import org.json.JSONArray;
  43. import org.json.JSONException;
  44. import org.json.JSONObject;
  45. import org.w3c.dom.Text;
  46.  
  47. import java.io.BufferedReader;
  48. import java.io.BufferedWriter;
  49. import java.io.IOException;
  50. import java.io.InputStream;
  51. import java.io.InputStreamReader;
  52. import java.io.OutputStream;
  53. import java.io.OutputStreamWriter;
  54. import java.net.HttpURLConnection;
  55. import java.net.MalformedURLException;
  56. import java.net.URL;
  57. import java.net.URLEncoder;
  58.  
  59. public class MainActivity extends AppCompatActivity {
  60.  
  61.     String Json_STRING;
  62.     TextView textView;
  63.  
  64.  
  65.     @Override
  66.     protected void onCreate(Bundle savedInstanceState) {
  67.         super.onCreate(savedInstanceState);
  68.         setContentView(R.layout.activity_main);
  69.         new BackgroundTask().execute();
  70.          //new line
  71.  
  72.  
  73.     }
  74.  
  75.  
  76.  
  77.  
  78.     /*public void getJSON(View view) {
  79.  
  80.         new BackgroundTask().execute();
  81.  
  82.     }*/
  83.  
  84.  
  85.     class BackgroundTask extends AsyncTask<Void, Void, String> {
  86.  
  87.         String json_url;
  88.         String JSON_STRING;
  89.  
  90.         @Override
  91.         protected void onPreExecute() {
  92.  
  93.             json_url = "http://10.0.2.2/json_comments.php";
  94.         }
  95.  
  96.         @Override
  97.         protected String doInBackground(Void... params) {
  98.             try {
  99.                 URL url = new URL(json_url);
  100.                 HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  101.                 InputStream inputStream = httpURLConnection.getInputStream();
  102.                 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  103.                 StringBuilder stringBuilder = new StringBuilder();
  104.                 while ((JSON_STRING = bufferedReader.readLine()) != null) {
  105.  
  106.                     stringBuilder.append(JSON_STRING + "n");
  107.                 }
  108.  
  109.                 bufferedReader.close();
  110.                 inputStream.close();
  111.                 httpURLConnection.disconnect();
  112.                 return stringBuilder.toString().trim();
  113.             } catch (MalformedURLException e) {
  114.                 e.printStackTrace();
  115.             } catch (IOException e) {
  116.                 e.printStackTrace();
  117.             }
  118.  
  119.             return null;
  120.         }
  121.  
  122.         @Override
  123.         protected void onProgressUpdate(Void... values) {
  124.             super.onProgressUpdate(values);
  125.         }
  126.  
  127.         @Override
  128.         protected void onPostExecute(String result) {
  129.             TextView textView = (TextView)findViewById(R.id.textView2);
  130.             textView.setText(result);
  131.             Json_STRING = result;
  132.         }
  133.  
  134.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top