0

In my controller, I am passing data to the model using the following code:

$data = array(
    'gid'   =>  $this->input->post('gid'),
    'name'  =>  $this->input->post('name'),
    'pic'   =>  $this->input->post('pic'),
    'link'  =>  $this->input->post('link')
);  
var_dump($data);
$this->Login_model->insert_entry($data);

In my model, what I want to do is use the gid value as part of an SQL statement, like so:

$get_gid = $this->db->query('SELECT * FROM users WHERE gid = $gid');

Obviously this doesn't work, so I'm just wondering how I get the gid from $data and use it in my SQL statement?

Tested using

$get_gid = $this->db->where('gid', $data['gid'])->get('users');
print_r($get_gid);

However output is:

CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #33 [result_array] => Array ( ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => 0 [row_data] => )

4 Answers 4

0

Did you try gid = $data['gid']

I assume that yours model method looks like this:

insert_entry($data)
{
     here active record or query...
 }

If yes try to display query to see if $data['gid'] is visible there

You can try it by

$this->db->get_compiled_select();

Or after query runs

$this->db->last_query();
Sign up to request clarification or add additional context in comments.

Comments

0

Try this way:

$data = array(
 'gid'   =>  $this->input->post('gid'),
 'name'  =>  $this->input->post('name'),
 'pic'   =>  $this->input->post('pic'),
 'link'  =>  $this->input->post('link')

);

$gid = $data['gid'];

$this->db->where('gid',$gid);
$this->db->from('users');
$query = $this->db->get(); 
if($query)
{
    //you can return query or you can do other operations here like insert the array data
    //$this->db->insert('yourtable',$data);
    return $query;
}
else
{
    return FALSE;
}

Comments

0

You can try:

$get_gid = $this->db->query('SELECT * FROM users WHERE gid = '.$data['gid'].');

Comments

0

You just Forget after query $query->result().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.