search - CodeIgniter: How to join two table columns and use like active record for querying both? -


public function search($query, $limit) {     // output     $output = "";     // query     $this->db->select("*");     $this->db->from("products");     $this->db->like("brand", $query);     $this->db->or_like("model", $query);     $this->db->limit($limit);     $query = $this->db->get();     // 0     if ($query->num_rows() == 0) {         $output .= "no results found";         return $output;     }     // result     foreach ($query->result_array() $row) {         // uri         $uri2 = "{$this->base_url}specifications/{$row['brand']}-{$row['model']}";         $uri2 = str_replace(" ", "-", $uri2);         // price format         $row['price'] = number_format($row['price']);         // image url         $image = "{$this->base_url}assets/images/products/{$row['category']}-{$row['brand']}-{$row['model']}/thumb.png";         $image = str_replace(" ", "-", $image);         $output .= "<ul class=\"product\">\n             <a href=\"{$uri2}\">\n                 <li class=\"product-image\"><img src=\"{$image}\" height=\"108\" width=\"57\" alt=\"\"></li>\n                 <li class=\"product-brand\">{$row['brand']}</li>\n                 <li class=\"product-model\">{$row['model']}</li>\n                 <li class=\"product-price\">{$row['price']} <span class=\"green\">pkr</span></li>\n             </a>\n         </ul>\n";     }     // return     return $output; } 

here 3 types of queries:

1- query contains brand (i results)
2- query contains model (i results)
3- query contains both (i no results)

how accomplish above 3 tasks?

it seems performing kind of search, there result want coming controller or view, jst make there if condition as

if ($brand_val != '' ) {  //put query here }  if ($model_val  != '' ) {  //put query here }  if ($brand_val != '' && $model_val  != ''   ) {  //put query here } 

hope give idea


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -