duanpin5168 2017-08-13 17:00
浏览 44
已采纳

Codeigniter获取mysql值

Can someone please guide me how I can fetch mysql row's value for "pk" to the $response variable to be able to allow the script to unfollow users automatically. I have already tried the script and it does unfollow when an pk id is provided but I want to automatically fetch it from mysql to be able to run it. Thank you for any help provided.

These are the methods I tried with no success:

$this->db->select('pk');
$this->model->from(INSTAGRAM_FOLLOW_TB);
$this->db->where("id = '11'");
$query1 = $this->db->get();
$result =  $query1->result();

Main ID that only unfollow this ID- created by Mushfik Media,

$response = $i->unfollow($result); 

I have also tried

$accounts = $this->model->fetch("*", INSTAGRAM_ACCOUNT_TB, "id = '11'");

$response = $i->unfollow($accounts->pk);

But didn't work. $NEED MYSQL DATA VALUE is where the value is supposed to be echoed but doesn't

case 'unfollow':
    try {
        $result = $i->getSelfUsersFollowing();

        if(!empty($result) && $result->status == "ok" && !empty($result->users)){

            $response = $i->unfollow($NEED MYSQL DATA VALUE); 
            $response = $response->status;
            $CI =& get_instance();
            $CI->load->model('Schedule_model', 'schedule_model');
            $lang = $CI->db->insert(INSTAGRAM_FOLLOW_TB, array(
                    "pk" => $row->pk,
                    "name" => $row->username,
                    "type"         => $data->schedule_type,
                    "uid"          => $data->uid,
                    "account_id"   => $data->account,
                    "account_name" => $data->name,
                            "created"      => NOW
                    ));
        }

    } catch (Exception $e){

        $response = $e->getMessage();
    }

break;
  • 写回答

1条回答 默认 最新

  • duanji1026 2017-08-13 17:42
    关注

    Maybe something like this to get your pk:

    $query1 = $this->db->select('pk')
        ->from(INSTAGRAM_FOLLOW_TB)
        ->where('id', 11)
        ->get();
    
    if( $query1->num_rows() == 1 ){
        $row =  $query1->row(); 
        $response = $i->unfollow( $row->pk );
    }
    

    Regarding your information that you are trying to use $this when not in object context, because you are in a helper, you need to get the CI super object. So, if you were trying to use $this->db, you would do this:

    $CI =& get_instance();
    // Now you can use $CI->db
    // and anything you would normally
    // access via $this in a controller
    // or model
    

    OK, finally to show an example of how to order or limit a query:

    $query1 = $this->db->select('pk')
        ->from(INSTAGRAM_FOLLOW_TB)
        ->where('id', 11)
        ->order_by('your_timestamp_field', 'ASC') // This would order by timestamp in ascending order
        ->limit(1) // This would limit to a single row
        ->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用yolov5-7.0目标检测报错
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备