2017-08-13 49 views
0

有人可以请指导我如何获取“pk”的mysql行值到$ response变量,以便脚本能够自动取消关注用户。我已经尝试过这个脚本,并且在提供pk id时它会取消关注,但我想从mysql自动获取它以便能够运行它。感谢您提供的任何帮助。Codeigniter获取MySQL值

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

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

主ID,只有取消关注由Mushfik媒体创造了这个ID-,

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

我也曾尝试

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

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

但没有奏效。 $ NEED MYSQL数据值是其中值是应该呼应,但并不

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; 

回答

0

也许这样的事情让你的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超级对象。所以,如果你试图用$这个 - >分贝,你可以这样做:

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

OK,终于以显示如何订购或限制查询的例子:

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

谢谢,但实际上并没有带来pk值 – user3498121

+0

因为这是事实,所以需要更多的信息。您可以查看实际的SQL查询以满足您的需求: $ this-> db-> last_query(); 我的查询有一个固定的ID为11,你可能需要改变。 –

+0

这是在error_log上显示的错误:[13-Aug-2017 22:54:07 Europe/London] PHP致命错误:使用$ this而不是在/home/testt/public_html/instagram_helper.php中的对象上下文中811 – user3498121