我有这个代码:
function search($terms){
$query = $this->db->get_where('products',"name LIKE '%$terms%' OR description LIKE '%$terms%'");
$product = $query->result_array();
foreach($product as $p):
$query2 = $this->db->get_where('categories', array('cat_id' => $p['prod_category']));
$category = $query2->row_array();
$product['category'] = $category['cat_link'];
endforeach;
return $product;
}
在我的搜索功能中。它将返回如下内容:
Array(
[0] => Array(
[prod_id] => 5
[prod_name] => Product
[prod_category] => 1
)
但我追求的是:
Array(
[0] => Array(
[prod_id] => 5
[prod_name] => Product
[prod_category] => Category1
)
来自我的 id 为 1 的类别的名称。这是在我的“类别”表中。foreach 循环不是完成此任务的正确方法,但它是什么?