【发布时间】:2021-08-05 12:13:03
【问题描述】:
我只想获取特色产品。我在数据库 product_type 中定义了一个列,其中可以列出四种类型的产品(热卖、新上市、当日特价和特色产品)强文本,这是可选的。
块引用
Here is my model|query code in codeigniter
public function featured_product()
{
$arrResult = array();
$this->db->select('*');
$this->db->from('product');
$this->db->where("product_type","featured");
$result = $this->db->get()->result_array();
if(!empty($result))
{
$arrResult['result'] = $result;
}
else
{
$arrResult['result'] = '';
}
return $arrResult ;
}
当我尝试在 api 中获取整个产品列表时,我得到了结果,但我只想显示特色产品。
【问题讨论】:
-
如果为时不晚,请更改数据库设计,以免在数据库列中使用逗号分隔列表。 stackoverflow.com/questions/3653462/…
-
嘿@RiggsFolly 感谢您的建议,我的意思是修改数据库,但对于知识前景,我们可以使用我上面定义的方式。我的代码在这里错了吗?如果我的代码错了,应该用这种方式解决什么问题。
标签: php mysql api codeigniter