Using database results in the controller

Hi there

I hope someone can help me as I am really stuck with this. I am using Ion_auth to build my login to an application but the principle is universal, I just don't know it!!!

I want to query a 'users' table and use the results to insert into a different table.

Here's the Model...
class Login_model extends CI_Model {
     function __construct() {
        // Call the Model constructor
    function get_user()
        $username = $this->session->userdata('username');
        $password = $this->session->userdata('password');
        $this->db->where('email', $username);
        $this->db->where('password', $password);
        $query = $this->db->get('users', 1);
        if($query->num_rows == 1)
            $results = $query->row();
            return     $results;

And the controller...
class Campaign extends CI_Controller {

    function __construct()
    function add()
        //Load the model

                $user = $this->Search_model->get_user();
        $sector = $user->sector;

        $insert = array(
                'c_sector'=>$sector, //this is the problem field!!!!
            $this->db->insert('campaigns', $insert);
            $this->session->set_userdata('campaign', $this->db->insert_id());

Can anyone help or explain (as clearly as possible please, like you're talking to an idiot ;-) !) how to use data you retrieve from a query in the controller?


if($this->query->num_rows() > 0)
    return $this->query->row();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.