title: search mysql data in two tables with custom search options
body: <p>Hi friends i have a custom search function in my website. Search is depending on two tables such as,
  <strong>product_table</strong></p>
  
  <pre><code>CREATE TABLE `product_table` (
   `product_id` int(11) NOT NULL auto_increment,
   `product_name` varchar(100) NOT NULL,
   `country` varchar(200) NOT NULL,
   `added_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
   PRIMARY KEY  (`product_id`));
  </code></pre>
  
  <p><strong>multiple_table</strong></p>
  
  <pre><code>CREATE TABLE `multiple_table` (
   `multi_id` int(11) NOT NULL auto_increment,
   `cat_id` int(11) NOT NULL,
   `product_id` int(11) NOT NULL,
   PRIMARY KEY  (`multi_id`));
  </code></pre>
  
  <p>I am giving option to users for search by one or more fields as  <code>product_name,country,cat_id,added_time</code></p>
  
  <p>my search function as follows,</p>
  
  <pre><code>if(isset($_GET['s_button'])){
  $sql2="SELECT a.product_id FROM product_table a, multiple_table b WHERE b.product_id= a.product_id ";
  $where=array();
  $values = array();
  $types = '';
  if(!empty($_GET['search_cat'])){
  $search_cat=clean($_GET['search_cat']);
  $where[]="AND cat_id='".$search_cat."'";
  }
  if(!empty($_GET['product_country'])){
  $country=clean($_GET['product_country']);
  $where[]="AND country='".$country."'";
  }
  if(!empty($_GET['model'])){
  $keyword=clean($_GET['model']);
  $where[]="AND product_name LIKE '%".$keyword."%'";
  }
  $sql2 .= implode($where). " ORDER BY a.product_id ";
  }else{
  $sql2 = "SELECT product_id FROM product_table ORDER BY Rand()";
  }
  </code></pre>
  
  <p>But this makes some incorrect and huge number of results and also searching takes too much of time.I don't know why is that.I have heard about MYSQL VIEWs does it make any sense for doing this? or do i have any easy way to make this happen? thanks</p>