【发布时间】:2015-11-02 07:22:44
【问题描述】:
查询运行基于 2 个 id,但我得到一个输出值
输入:
public function get_place_order_category($id)
{
/* $id = 1,2;*/
$ids = explode(',',$id);
foreach($ids as $catid)
{
$this->db->where('product_id =',trim($catid));
$query = $this->db->get('products');
return $query->result_array();
}
}
输出:
Array
(
[0] => Array
(
[product_id] => 12
[product_name] => Product1
[product_code] => pro12345
[product_price] => 200.00
[product_newprice] => 0.00
[size] => 0-6M , 0-9M ,9-12M
[product_front] => 1446200664.JPG
[product_back] => 14462006641.JPG
[product_left] => 14462006642.JPG
[product_right] => 14462006643.JPG
[product_description] =>
[styling_tips] =>
[category_id] => 62
[user_id] => 5
[status] => 1
[parent_id] => 42
[qty] => 4
[promo_id] => 0
[etc4] => 0
[etc5] => 0
)
)
【问题讨论】:
-
您想要基于所有通过的 id 的记录吗?
-
输出来自
return $query->result_array();这里?? -
当然你只会得到一个,一旦
return行命中,你的方法就结束了,要么先收集所有结果,要么只选择带有IN子句的行 -
只需将分解后的 id 传递给
->where_in方法,不需要循环等。 -
我使用 wher_in 查询 @Ghost 但我收到错误您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的 'IN ('12', '13')' 附近使用正确的语法 SELECT * FROM (
products) WHEREproduct_id= IN ('12' , '13')
标签: php mysql codeigniter