Welcome Guest, Not a member yet? Register   Sign In
some help with database to save in session
#1

[eluser]Kentus[/eluser]
I have next problem and i'm a little confused.
i have my model here:

function get_money()
{

$this->db->select('money');
$this->db->from('membership');
$this->db->where('username',$this->session->userdata('username'));

$q = $this->db->get();

if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}

}

i have my controller here:

function validate_credentials()
{
$this->load->model('membership_model');
$query=$this->membership_model->validate();
if($query)
{
$data=array(
'username'=>$this->input->post('username'),
'is_logged_in'=>true,
'rows' => $this->membership_model->get_money()
);


$this->session->set_userdata($data);
redirect('site/members_area');

}

and my view page where i call the session:
<?php
$name=$this->session->userdata('username');
$money=$this->session->userdata('rows->money');
echo $this->session->userdata('rows->money');
echo $this->session->userdata('rows');
?>

and the result is a text: Array that's come from this code: echo $this->session->userdata('rows');

what i can't see?
in my mind is like that:
i have a model who retrive all money rows where username= username's session
i have a controler that retrive all rows and put in data['rows'] and send to my session variable.
i use the session rows..
but don't works.. pls help me
#2

[eluser]duellsy[/eluser]
do

var_dump($this->session->userdata(‘rows’));

to see what's actually being returned for you to play with, and go from there
#3

[eluser]Kentus[/eluser]
Arrayarray(1) { [0]=> object(stdClass)#14 (3) { ["gamesAvailable"]=> string(3) "100" ["money"]=> string(1) "0" ["level"]=> string(1) "1" } }

i think i'm confused with showing this.
how i can save for example gamesAvailable
$gA=$this->session->userdata(‘rows->gamesAvailable’) or
$gA=$this->session->userdata(‘rows[gamesAvailable]’)

thanks
#4

[eluser]Kentus[/eluser]
finally...i make a foreach and i save him Smile
thanks for helping.
#5

[eluser]duellsy[/eluser]
In this case...

$row = $this->session->userdata(‘rows’);
$money = $row[0]->gamesAvailable;
#6

[eluser]Kentus[/eluser]
thanks.. this is more fast that my foreach solution.




Theme © iAndrew 2016 - Forum software by © MyBB