Advertisement
Guest User

Untitled

a guest
Feb 28th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3.    //fetch.php
  4.  
  5. if(isset($_POST["query"])){
  6.  
  7.  $connect = mysqli_connect("private", "private", "private", "private");
  8.  
  9.  $request = mysqli_real_escape_string($connect, $_POST['query']);
  10.  
  11.  $query = "
  12.  
  13.   SELECT * FROM search_product
  14.  
  15.   WHERE produktnamn LIKE '%".$request."%'
  16.  
  17.   OR specifikationer LIKE '%".$request."%'
  18.  
  19.  ";
  20.  
  21.  $result = mysqli_query($connect, $query);
  22.  
  23.  $data = array();
  24.  
  25.  $html = '';
  26.  
  27.  $html .= '
  28.  
  29.   <table class="table table-bordered table-striped">
  30.  
  31.    <tr>
  32.  
  33.     <th>Name</th>
  34.  
  35.     <th>Specifications</th>
  36.  
  37.    </tr>
  38.  
  39. ';
  40.   }
  41.  }if(mysqli_num_rows($result) == 0){
  42.   $data = 'No Data Found';
  43.   $html .= '
  44.    <tr>
  45.     <td colspan="3">No Results Found</td>
  46.  </tr>
  47.    ';
  48.  }
  49.  
  50.  $html .= '</table>';
  51.  
  52.  if(isset($_POST['typehead_search']))
  53.  {
  54.   echo $html;
  55.  }
  56.  else
  57.  {
  58.   array_unique($data);
  59.   echo json_encode($data);
  60.  }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement