Session vs Query Help

#1
[eluser]draconus[/eluser]
Okay, So I have the following info in session:

Code:
$session['id'] = $this->session->userdata('id');
        $session['firstName'] = $this->session->userdata('firstName');
        $session['lastName'] = $this->session->userdata('lastName');
        $session['email'] = $this->session->userdata('email');
        $session['address'] = $this->session->userdata('address');
        $session['address2'] = $this->session->userdata('address2');
        $session['city'] = $this->session->userdata('city');
        $session['state'] = $this->session->userdata('state');
        $session['country'] = $this->session->userdata('country');
        $session['postal'] = $this->session->userdata('postal');
        $session['home'] = $this->session->userdata('home');
        $session['business'] = $this->session->userdata('business');
        $session['cell'] = $this->session->userdata('cell');
        $session['profile'] = $this->session->userdata('profile');

Which works great, but of course, every record has the same data. I created a query that pulls based on the id of the record and tryed to return it to the view:
Code:
function profile(){
        $this->load->model('users');
        $this->db->where('id',$this->uri->segment(3));
        $data = $this->db->get('users');        
        
        $this->load->view('profile', $data);
    }

This is supposed to give users the profile they click from the search, but it pulls the session data unfortunetly, whose scope is overriding my query results.

Any suggestions here on how i can pull the data more explicitly in the view?

#2
[eluser]Tri Dang[/eluser]
I guess you put this code in the view:
Code:
$session['id'] = $this->session->userdata('id');
        $session['firstName'] = $this->session->userdata('firstName');
        $session['lastName'] = $this->session->userdata('lastName');
        $session['email'] = $this->session->userdata('email');
        $session['address'] = $this->session->userdata('address');
        $session['address2'] = $this->session->userdata('address2');
        $session['city'] = $this->session->userdata('city');
        $session['state'] = $this->session->userdata('state');
        $session['country'] = $this->session->userdata('country');
        $session['postal'] = $this->session->userdata('postal');
        $session['home'] = $this->session->userdata('home');
        $session['business'] = $this->session->userdata('business');
        $session['cell'] = $this->session->userdata('cell');
        $session['profile'] = $this->session->userdata('profile');

How about, change from $this->session->userdata('id') to $id (assume your array $data has 'id' as a key of its members) and similar for all other values?

#3
[eluser]draconus[/eluser]
No, missing my point... You see, the session variables and the search are only the same in that the data names are the same. ex. id, firstname, etc... what I did to work around this is I did a for each loop in the view and returned the result as an object... But of course i would prefer not to have to loop through the data

#4
[eluser]Tri Dang[/eluser]
Sorry if I don't understand you clearly.

What I see here is you pass in $data variable to the view. And what is your code in the view to display the profile data?

If you use:
Code:
function profile(){
    $this->load->model('users');
    $this->db->where('id',$this->uri->segment(3));
    $query = $this->db->get('users');
    $data = $query->row_array();
    $this->load->view('profile', $data);
}
Then in your view, $id, $firstName etc... will point to the correct value in the database (assume your users table has fields with these names).


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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