我正在codeigniter中创建一个web应用程序,它根据用户添加到关键字列表中的关键字从用户数据库中检索帖子。 我试图检索所有与用户的关键字的职位,但是,而也有复式在帖子查询只返回一行数据
这是关键字相匹配的是从我的模型
此函数检索它的函数只返回一个职位用户关键字
function user_keywords($user_id) {
//Get all the user keywords
$q = $this->db->select('keywords')
->from('keywords')
->where('U_id',$user_id)
->get();
$words = $q->result_array();
return $words;
}
该函数获取职位
function get_latest_pheeds() {
$this->load->helper('date');
$time = time();
$keyword = $this->user_keywords($this->ion_auth->user_id);
foreach($keyword as $word) {
$q = $this->db->select('user_id,pheed_id,datetime,pheed,COUNT(pheed_comments.comment_id) as comments')
->from('pheeds')
->join('pheed_comments','pheed_comments.P_id=pheeds.pheed_id','left')
->like('pheed',$word['keywords'])
->order_by('datetime','desc')
->get();
}
$rows = $q->result_array();
return $rows;
}
我的控制器编码它的JSON
function latest_pheeds() {
if($this->isLogged() == true) {
$this->load->model('pheed_model');
$data = $this->pheed_model->get_latest_pheeds();
echo json_encode($data);
}
return false;
}
我真的很感激帮助
你确定这个问题是不是在你的选择()或result_array()方法? – Mike
'get_latest_pheeds()'方法中的'$ q'将有最后一个查询。在提出更好的方法之前,'$ word ['keywords']'包含了什么?一个关键字? “关键字”表中的“pheeds”表(在“pheed”字段中)也完全一样吗? – ifaour
$ word ['keywords']包含从user_keywords()方法返回的关键字 – MrFoh