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;
}
在这里,我做了三种类型的查询:
1- 只包含品牌的查询(我得到结果)
2- 只包含模型的查询(我得到结果)
3- 两者都包含的查询(我没有得到结果)
如何完成以上三项任务?