我有这个代码我需要用来从数据库中获取结果,我在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用作数组?
答案 0 :(得分:1)
这很简单。 只需使用$ this-&gt; db-&gt; where_in('broadcast_id',$ bid);
相反,如果$ this-&gt; db-&gt; where('broadcast_id',$ bid);
https://ellislab.com/codeigniter/user-guide/database/active_record.html#select
答案 1 :(得分:0)
最好有一个查询来获取Feed吗?
$this->db->select("ih_noticeboard.*");
$this->db->from("ih_noticeboard");
$this->db->join("ih_broadcastors", "ih_noticeboard.broadcast_id = ih_broadcasters.broadcast_id");
$this->db->where("ih_broadcastors.broadcast_subscribers", $id);
$result->db->get()->result();
答案 2 :(得分:0)
假设您要在表中选择
name ='jane'和broadcast_id = 2#作为示例
$bid=array(
'name'=>'jane',
'broadcast_id'=>'2'
)
$this->db->where($bid);
$this->db->from($table_name);
$query = $this->db->get()->result_array();
return $query;
请注意,必须格式化 $ bid as数组的格式以适合要查询的下一个数据库表。您可以使用 foreach循环,例如
foreach ($ress as $row){
$bid = array(
'name'=>$row['name'],
'broadcast_id'=>$row['id']
);
}