Advertisement
michaelyuen

Untitled

Feb 20th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2.     class someClass {
  3.         private $data;
  4.        
  5.         public function __construct() {
  6.             global $con;
  7.             $this->con = $con;
  8.         }
  9.    
  10.         public function getSearch($search_array);
  11.             $this->getSearch = '';
  12.             foreach ($search_array as $k => $v) {
  13.                 $likes[] = "$k LIKE '%$v%'";
  14.             }
  15.             $where = implode(' AND ',$likes);
  16.             $query = "SELECT title,cat_name,country_name,state_name,city_name
  17.                             FROM classified
  18.                             LEFT JOIN user on classified.user_id=user.id
  19.                             LEFT JOIN category on classified.category_id=category.id
  20.                             LEFT JOIN countries on user.country=countries.id
  21.                             LEFT JOIN states on user.state=states.id
  22.                             LEFT JOIN cities on user.city=cities.id
  23.                             WHERE $where";
  24.             if (!$result = $this->con->query($query)) {
  25.                 $this->getSearch->error = 'Error - Connection, Search : ' . $this->con->error;
  26.                 return false;
  27.             }
  28.             if ($result->num_rows == 0) {
  29.                 $this->getSearch->error = 'Warning - Search: No Record Found';
  30.                 return false;
  31.             }
  32.             WHILE ($row = $result->fetch_assoc()) {
  33.                 $data[] = $row;
  34.             }
  35.             return $data;
  36.     }
  37.    
  38.     $someClass = new someClass;
  39.    
  40.     if (ISSET($_POST['search'])) {
  41.         $search_array = $_POST;
  42.         unset($search_array['search']);
  43.         $result = $someClass->getSearch($search_array);
  44.         echo $result = (is_array($result)) ? print_r($result) : $someClass->getSearch->error;
  45.     }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement