Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2. header('Content-Type: application/json');
  3. //--------------------------------------------------------------------------
  4. // Example php script for fetching data from mysql database
  5. //--------------------------------------------------------------------------
  6. $host = "localhost";
  7. $user = "";
  8. $pass = "";
  9.  
  10. $databaseName = "";
  11. $tableName = "suggestions";
  12.  
  13. //--------------------------------------------------------------------------
  14. // 1) Connect to mysql database
  15. //--------------------------------------------------------------------------
  16.  
  17. $con = mysql_connect($host,$user,$pass);
  18. $dbs = mysql_select_db($databaseName, $con);
  19. $name=$_REQUEST['name'];
  20. //--------------------------------------------------------------------------
  21. // 2) Query database for data
  22. //--------------------------------------------------------------------------
  23.  
  24. $result = mysql_query("SELECT * FROM $tableName where name like '$name%%'"); //query
  25. //$array = mysql_fetch_row($result); //fetch result
  26. $rows = array();
  27. while($r = mysql_fetch_assoc($result)) {
  28. $rows['results'][] = $r;
  29. }
  30. //--------------------------------------------------------------------------
  31. // 3) echo result as json
  32. //--------------------------------------------------------------------------
  33.  
  34. echo json_encode($rows);
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement