0

我是 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();
    }
4

3 回答 3

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();
    }

}
于 2013-10-09T09:37:20.807 回答
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();
}
}
于 2013-10-09T09:40:14.427 回答
0

这应该在模型中完成。
使用 avtice 记录你可以这样做

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()
}
于 2013-10-09T10:01:27.917 回答