我需要使用这段代码从数据库获取结果,我正在使用 codeigniter。这就是查询的样子,
$this->db->select('*');
$this->db->where('broadcast_id', $bid);
$query = $this->db->get('ih_noticeboard');
$result = $query->result();
if($query->num_rows() < 1){
$data = "no feed ";
}else{
$data = $result;
}
where子句中的$bid
就是从这段代码中获取的,
$this->db->select('broadcast_id');
$this->db->where('broadcast_subscribers', $id);
$query = $this->db->get('ih_broadcastors ');
if($query->num_rows() < 1){
$data = "user not subscribed to any broadcasting";
}else{
$ress = $query->result();
foreach ($ress as $row){
$bid = $row->broadcast_id;
}`
现在 select 只使用了一个 $bid,如何将 $bid 用作数组?
最佳答案
这很简单。 只需使用 $this->db->where_in('broadcast_id', $bid);
相反,如果 $this->db->where('broadcast_id', $bid);
https://ellislab.com/codeigniter/user-guide/database/active_record.html#select
关于php - Codeigniter db select where 作为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499080/