我是php和codeigniter的初学者。任何人都将这个php程序作为codeigniter格式?
if ($user_id > 0){
$follow = array();
$fsql = "select user_id from following
where follower_id='$user_id'";
$fresult = mysql_query($fsql);
while($f = mysql_fetch_object($fresult)){
array_push($follow, $f->user_id);
}
if (count($follow)){
$id_string = implode(',', $follow);
$extra = " and id in ($id_string)";
}else{
return array();
}
答案 0 :(得分:0)
试试这个:
if ($user_id > 0){
$follow = array();
$rs = $this->db->select('user_id')->where('follower_id', $user_id)->get('following')->result_array();
if( is_array( $rs ) && count( $rs ) > 0 ){
$follow = array();
foreach( $rs as $key => $each ){
$follow[] = $each['user_id'];
}
}
if (count($follow)){
$id_string = implode(',', $follow);
$extra = " and id in ($id_string)";
}else{
return array();
}
}
答案 1 :(得分:0)
if ($user_id > 0)
{
$follow = array();
$qry = "select user_id from following where follower_id='$user_id'";
$res = $this->db->query(qry);
foreach($res->result() as $row)
{
array_push($follow, $row->user_id);
}
if (count($follow))
{
$id_string = implode(',', $follow);
$extra = " and id in ($id_string)";
}
else
{
return array();
}
}
答案 2 :(得分:0)
这应该在模型中完成 使用活动记录你可以这样做
function getFriends($user_id){
return $this->db
->select('user_id')
->where('follower_id',$user_id)
->get('following')
->result_array() // for single object use row_array()
}