Advertisement
michaelyuen

Untitled

Feb 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2. include "dbcon.php";
  3.  
  4. class DataOperation extends database {
  5. public function search($table,$search_name) {
  6.  
  7.     $sql = "SELECT * FROM ".$table ." WHERE title LIKE '%$search_name%'";
  8.  
  9.     $query = mysqli_query($this->con,$sql);
  10.     $count = mysqli_num_rows($query);
  11.     if ($count == 0) {
  12.         return false;
  13.     }
  14.  
  15.     WHILE ($row = mysqli_fetch_assoc($query)){
  16.         $array[]=$row;
  17.     }
  18.     return $array;
  19. }
  20.  
  21. ?>
  22.  
  23. // search.php
  24.  
  25. <?php
  26. $obj = new DataOperation;
  27.  
  28. if (strlen($search_name) > 2 ){    
  29.     $row = $obj->search('classified',$search_name);
  30.     foreach ($row as $data) {
  31.         echo '<h4>'.$data['title'].'</h4>';
  32.         echo '<h4>'.$data['description'].'</h4>';
  33.         echo '<h4>'.$data['id'].'</h4>';
  34.     }
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement