Advertisement
Guest User

Untitled

a guest
May 8th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. <?php
  2. $DB_USER='root';
  3. $DB_PASS='';
  4. $DB_HOST='localhost';
  5. $DB_NAME='pfe';
  6.  
  7. $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  8. /* check connection */
  9. if (mysqli_connect_errno())
  10. {
  11. printf("Connect failed: %sn", mysqli_connect_error());
  12. exit();
  13. }
  14.  
  15. $comm = $_GET['comm'];
  16. $mysqli->query("SET NAMES 'utf8'");
  17. $sql="SELECT nomco FROM commune where idwi=".$comm;
  18. $result=$mysqli->query($sql);
  19.  
  20. while($e=mysqli_fetch_assoc($result))
  21. {
  22. $output[]=$e;
  23. }
  24.  
  25. print(json_encode($output));
  26. $mysqli->close();
  27.  
  28. ?>
  29.  
  30. public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
  31. EditText idtxt;
  32. TextView txtaffich;
  33.  
  34. ArrayAdapter<String> listadapter;
  35. ListView listView;
  36. ArrayList<String> listcom = new ArrayList<>();
  37. HttpURLConnection httpURLConnection;
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.activity_main);
  42. idtxt = (EditText) findViewById(R.id.editTextId);
  43.  
  44.  
  45. listView = (ListView)findViewById(R.id.listView);
  46. listadapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listcom);
  47. listView.setAdapter(listadapter);
  48. listView.setOnItemClickListener(this);
  49.  
  50. }
  51.  
  52. public void send(View view) {
  53. String id = idtxt.getText().toString();
  54. if (id.length() == 0 ) {
  55. Toast.makeText(MainActivity.this, "Vous devez remplir les champs", Toast.LENGTH_LONG).show();
  56. }else {
  57. Toast.makeText(this, "wait...", Toast.LENGTH_SHORT).show();
  58.  
  59. new SignupActivity().execute(id);
  60.  
  61. Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
  62.  
  63. }
  64. }
  65.  
  66. public class SignupActivity extends AsyncTask<String, Void, String> {
  67.  
  68.  
  69. ArrayList<String> me;
  70.  
  71.  
  72. protected void onPreExecute() {
  73. super.onPreExecute();
  74. me =new ArrayList<>();//pour lis
  75.  
  76. }
  77.  
  78. @Override
  79. protected String doInBackground(String... arg0) {
  80. String idenv = arg0[0];
  81. InputStream is=null;
  82.  
  83. String link;
  84. String data;
  85. BufferedReader bufferedReader2;
  86. String result="";
  87.  
  88. try {//le message a envoyer + mail
  89. //we append to this URL a ‘?’ mark and the variable values
  90. // separated by ‘&’ sign, these values will be passed to the server by HTTP GET method.
  91. data = "?comm=" + URLEncoder.encode(idenv, "UTF-8");
  92.  
  93. link = "http://192.168.43.93/pfe/select_spinner_com.php" + data;
  94.  
  95. URL url = new URL(link);
  96.  
  97. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  98.  
  99. is= con.getInputStream();
  100.  
  101. bufferedReader2 = new BufferedReader(new InputStreamReader(is));
  102.  
  103. String line2 = "";
  104. while ((line2 = bufferedReader2.readLine().toString()) != null) {
  105. result += line2;
  106.  
  107.  
  108. }
  109. } catch (Exception e) {
  110. return new String("Exception: " + e.getMessage());
  111. }
  112. try {
  113.  
  114. JSONArray jsonArray = new JSONArray(result);
  115. for (int ii = 0; ii < jsonArray.length(); ii++) {
  116. JSONObject jsonObject2 = jsonArray.getJSONObject(ii);
  117. me.add(jsonObject2.getString("nomco"));
  118. }
  119. } catch (JSONException e) {
  120. e.printStackTrace();
  121. }
  122. return null;
  123. }
  124. protected void onPostExecute(String result) {
  125.  
  126. listcom.addAll(me);//pour list view
  127. listadapter.notifyDataSetChanged(); }
  128. }
  129. }
  130.  
  131. <uses_permission android:name="android.permission.INTERNET" />
  132. <uses_permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  133.  
  134. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement