Welcome Guest, Not a member yet? Register   Sign In
Help creating retrieving session data from database needed pwetty pwease
#1

[eluser]Tom Taila[/eluser]
Ok let me start by saying sory for the long wounded explanation which follows :
so i have a login and logout function which work fine except for my login function i would like to display info about the user which is stored in my database table which is called 'members'. i know how to display it and start a session but i aint sure on how to pull the data from the database to store it in an array which can be used later whilst the user is logged in, ok so heres two codes that i have so far


this is from my model called "membership_model"
Code:
function login_validation() {
        $this->db->where('email', $this->input->post('email'));
        $this->db->where('password', md5($this->input->post('password')));
        $query = $this->db->get('members');
        
        if($query->num_rows == 1){
            return true;
        }
        
    }

and this is from my controller called "login"

Code:
function login_validation() {
        $this->load->model('membership_model');
        $query = $this->membership_model->login_validation();
        
        if($query) {
            $data = array(
                    'email' => $this->input->post('email'),
                    'is_logged_in' => true
            );
            
            $this->session->set_userdata($data);
            redirect('main');
        }
        
        else {
            $this->load->view('main_page');
        }
    }
    
    function logout() {
        $this->session->sess_destroy();
        redirect('main');
    }
}

thanks peoples Smile hope u guys can help this poor lil nooblet lol
#2

[eluser]Buso[/eluser]
you can retrieve single items by doing $item = $this->session->userdata('item');

for a complete array you will have to do it yourself i think
#3

[eluser]Tom Taila[/eluser]
yeaa i get that, the problem isnt displaying it or using it in other places the problem is getting the data there if that makes sense. i need to pull that data it from the database table, i think i need to insert something into this array:

if($query) {
$data = array(
'email' => $this->input->post('email'),
'is_logged_in' => true
);

its easy for the 'email' because thats what the user inputs to log in, but theres data that hasnt been input which i need pull from the database itself. I think i need to get that row from the table after analyzing the users email and then store that into the above array :S i may be wrong :S thanks for the quick response btw




Theme © iAndrew 2016 - Forum software by © MyBB