Using database results in the controller

#1
[eluser]bcarter[/eluser]
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!!!

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

Here's the Model...
Code:
class Login_model extends CI_Model {
    
     function __construct() {
        // Call the Model constructor
        parent::__construct();
    }
    
    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...
Code:
class Campaign extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->is_logged_in();
    }
    
    function add()
    {
        //Load the model
        $this->load->model('Search_model');

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

        $insert = array(
                'c_sector'=>$sector, //this is the problem field!!!!
                'c_title'=>$this->input->post('title'),
                'c_start'=>dbdate_converter($this->input->post('campaign_start')),
                'c_end'=>dbdate_converter($this->input->post('campaign_end')),
            );
            
            $this->db->insert('campaigns', $insert);
            $this->session->set_userdata('campaign', $this->db->insert_id());
            redirect('campaign/goals');        
            
        }
    }

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?

Thanks!

#2
[eluser]InsiteFX[/eluser]
Code:
if($this->query->num_rows() > 0)
{
    return $this->query->row();
}

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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