Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "mydb";//database details
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);//making a connection
  9. // Check connection
  10. if ($conn->connect_error) {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. $sql = "SELECT * FROM mytable";
  15. $result = $conn->query($sql);
  16. $myarray = array();
  17. $index=0;
  18. if ($result->num_rows > 0) {
  19. // output data of each row
  20. while($row = $result->fetch_assoc()) {
  21. $myarray[$index] =$row["firstname"];
  22. $index++;
  23. $myarray[$index] =$row["lastname"];//storing in the array
  24. $index++;
  25. $myarray[$index] =$row["email"];
  26. $index++;
  27. }
  28. } else {
  29. echo "0 results";
  30. }
  31. $conn->close();
  32. ?>
  33.  
  34. var substringMatcher = function(strs) {
  35. return function findMatches(q, cb) {
  36. var matches, substringRegex;
  37.  
  38. // an array that will be populated with substring matches
  39. matches = [];
  40.  
  41. // regex used to determine if a string contains the substring `q`
  42. substrRegex = new RegExp(q, 'i');
  43.  
  44. // iterate through the pool of strings and for any string that
  45. // contains the substring `q`, add it to the `matches` array
  46. $.each(strs, function(i, str) {
  47. if (substrRegex.test(str)) {
  48. matches.push(str);
  49. }
  50. });
  51.  
  52. cb(matches);
  53. };
  54. };
  55. $('#the-basics .typeahead').typeahead({
  56. hint: true, //here i used typeahead js code though i didnt mentioned here
  57. highlight: true,
  58. minLength: 1
  59. },
  60. {
  61. name: 'states',
  62. source: substringMatcher(states)
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement