2013-04-05 51 views
0
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(); 
    // zero 
    if ($query->num_rows() == 0) { 
     $output .= "No results found"; 
     return $output; 
    } 
    // result 
    foreach ($query->result_array() as $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; 
} 

在這裏,我做三種類型的查詢:只包含品牌(我得到的結果)
2-查詢包含僅包含模型(我得到的結果)
3-查詢CodeIgniter:如何加入兩個表列並使用類似於活動記錄查詢兩者?

1查詢這兩個(我沒有結果)

如何完成以上所有三個任務?

回答

0

看來你正在執行某種搜索,所以有結果,你想從控制器或視圖來了,你JST做,使那裏,如果這樣的條件,那麼做得一樣

if ($brand_val != '') 
{ //put your where query here } 

if ($model_val != '') 
{ //put your where query here } 

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

希望這會給出想法

0

用這個打印查詢。

echo $ this-> db-> last_query();

然後嘗試在您的phpmyadmin中執行該查詢

相關問題