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 に答える