Codeigniter 获取 mysql 值

Codeigniter get mysql value

有人可以指导我如何获取 mysql 行的 "pk" 值到 $response 变量,以便能够允许脚本自动取消关注用户。我已经尝试过该脚本,当提供 pk id 时它会取消关注,但我想自动从 mysql 获取它以便能够 运行 它。感谢您提供的任何帮助。

这些是我尝试过但没有成功的方法:

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

仅取消关注此 ID 的主要 ID - 由 Mushfik Media 创建,

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

我也试过了

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

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

但是没用。 $NEED MYSQL DATA VALUE 是应该回显但不回显的值

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;

也许这样可以让你的 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 );
}

关于您在不在对象上下文中尝试使用 $this 的信息,因为您在帮助程序中,您需要获取 CI 超级对象。所以,如果你试图使用 $this->db,你会这样做:

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

好的,最后展示一个如何排序或限制查询的例子:

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