Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "mydb";//database details
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);//making a connection
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT * FROM mytable";
- $result = $conn->query($sql);
- $myarray = array();
- $index=0;
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- $myarray[$index] =$row["firstname"];
- $index++;
- $myarray[$index] =$row["lastname"];//storing in the array
- $index++;
- $myarray[$index] =$row["email"];
- $index++;
- }
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
- var substringMatcher = function(strs) {
- return function findMatches(q, cb) {
- var matches, substringRegex;
- // an array that will be populated with substring matches
- matches = [];
- // regex used to determine if a string contains the substring `q`
- substrRegex = new RegExp(q, 'i');
- // iterate through the pool of strings and for any string that
- // contains the substring `q`, add it to the `matches` array
- $.each(strs, function(i, str) {
- if (substrRegex.test(str)) {
- matches.push(str);
- }
- });
- cb(matches);
- };
- };
- $('#the-basics .typeahead').typeahead({
- hint: true, //here i used typeahead js code though i didnt mentioned here
- highlight: true,
- minLength: 1
- },
- {
- name: 'states',
- source: substringMatcher(states)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement