gpt4 book ai didi

php - Codeigniter 通过传递逗号分隔值来获取数据

转载 作者:行者123 更新时间:2023-11-29 12:28:55 25 4
gpt4 key购买 nike

这是我的申请详细信息:在 mysql 数据库中,我有包含 id、描述和价格的 products 表。在 basket 表中,我的 products_id 格式为 1,2,3,即逗号分隔值。

现在,在 Controller 中,我通过此函数从购物篮表中获取了product_id列表:

$data['baskets'] = $this->baskets_model->get_all();
$pr_id=$this->baskets_model->get_all();

foreach ($pr_id as $pr){
$get_pr_info=$this->products_model->get_all($pr->product_id);
}

我在products_model模型中有这个函数:

public function get_all($ids=NULL) {
if($ids !== NULL) {
echo $ids;
}
else {
$query = $this->db->get('products');
return $query->result_array();
}
}

$ids 与 products_id 相呼应,为 1,2,3。现在,如何通过从 product 表传递此 products_id 来获取每个产品的详细信息并显示在购物篮中?如果我的问题不清楚,请发表评论。

最佳答案

希望对你有帮助

public function get_all($ids=NULL) 
{
$this->db->from('products');

if($ids !== NULL)
{
$this->db->where("id in ($ids)");//use this
//$this->db->where_in('id',$ids);//This may work but I think it will not give your right answer
//if your id like 1,2,3. this will not work i think but if you send only one id it will work.
}
$query = $this->db->get();
return $query->result_array();
}

关于php - Codeigniter 通过传递逗号分隔值来获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27896744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com