Welcome Guest, Not a member yet? Register   Sign In
array session didn't work
#1

[eluser]yudahebat[/eluser]
I have a controller
Code:
function v_cart()
    {
        $data['css']         = $this->css;
        $data['base']         = $this->base;
        $data['menu_web']     = $this->menu;
        $data['myrobots']     = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | Your cart';
        
        $this->output->enable_profiler(TRUE);
        $this->session->set_userdata(array('nama' => $this->input->post('nama'),'photo' => $this->input->post('photo'),'harga' => $this->input->post('harga'),'renttgl' => $this->input->post('renttgl'),'rettgl' => $this->input->post('rettgl')));
    
        $this->load->view('v_cart',$data);
    }

and view

Code:
<?php echo form_open('mrputucar/update_cart'); ?>
                <table width="645" border="0" cellpadding="0" cellspacing="0" class="tabel" >
                <tr>
                    <td width="130" class="tabel" align="center"><p>Car Type</p></td>
                    <td width="110" class="tabel" align="center"><p>Rent date</p></td>
                    <td width="110" class="tabel" align="center"><p>Return date</p></td>
                    <td width="80" class="tabel" align="center"><p>Duration</p></td>
                    <td width="100" class="tabel" align="center"><p>Price/day</p></td>
                    <td width="110" class="tabel" align="center"><p>Suhtotal</p></td>
                </tr>
                &lt;?php $query = $this->session->userdata();
                $user_array = $query->result_array();
                if(count($user_array) > 0)
                    {
                        foreach($user_array as $ua)
                        { ?&gt;
                <tr>
                    <td width="130" class="tabel"><p>&lt;?= $ua['nama'];?&gt;</p></td>
                    <td width="110" class="tabel"><p>&lt;?= $ua['renttgl'];?&gt;</p></td>
                    <td width="110" class="tabel"><p>&lt;?= $ua['rettgl'];?&gt;</p></td>
                    <td width="80" class="tabel"><p>&lt;?= (strtotime($this->session->userdata('rettgl')) - strtotime($this->session->userdata('renttgl'))) / 86400;?&gt; day</p></td>
                    <td width="100" class="tabel"><p>$ &lt;?= $ua['harga'];?&gt;</p></td>
                    <td width="110" class="tabel"><p>$ &lt;?= ((strtotime($this->session->userdata('rettgl')) - strtotime($this->session->userdata('renttgl'))) / 86400) * $this->session->userdata('harga');?&gt;</p></td>
                </tr>
                <tr>
                    <td colspan="4" class="tabel2"><p>&lt;?php echo form_submit('', 'send request'); ?&gt;</p></td>
                    <td  class="tabel2"><p>Total</p></td>
                    <td  class="tabel2"><p>$...</p></td>
                </tr>
                    &lt;?php }
                    } ?&gt;
                    
                </table>
                    &lt;?php echo form_close(); ?&gt;

when I run it, the array didn't work
its error
Code:
A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for CI_Session::userdata(), called in C:\xampp\htdocs\CI2\system\application\views\v_cart.php on line 22 and defined

Filename: libraries/Session.php

Line Number: 420
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: item

Filename: libraries/Session.php

Line Number: 422
Code:
Fatal error: Call to a member function result_array() on a non-object in C:\xampp\htdocs\CI2\system\application\views\v_cart.php on line 23

line 23 :
Code:
$user_array = $query->result_array();

whats wrong? I just wanna show my session on array. so every I input data from another views it will show as a session without replace last entry data
looks like cart system...
#2

[eluser]Thorpe Obazee[/eluser]
why not continue this post? http://ellislab.com/forums/viewthread/120290/
#3

[eluser]Thorpe Obazee[/eluser]
Do you know when to use result_array()?

Do you know how to use $this->session->userdata()?
#4

[eluser]yudahebat[/eluser]
I'm new on CI. I dont know how to use both off them very much.
I just know little bit bout $this->session->userdata()? from the user guide. its use to get session data
teach me more please. how to use it on array...
#5

[eluser]Thorpe Obazee[/eluser]
From the error, it says that you need to put a parameter in $this->session->userdata();

PS. You'll need to modify the controller that you store arrays in the sessions and loop through it. I suggest you work with the controller first that it actually does what you need it to do. I suggest you look at how the Cart class works.
#6

[eluser]yudahebat[/eluser]
i've do what you command and its error
Code:
Fatal error: Call to a member function result_array() on a non-object in C:\xampp\htdocs\CI2\system\application\views\v_cart.php on line 23
line 23
Code:
$user_array = $query->result_array();
#7

[eluser]Thorpe Obazee[/eluser]
[quote author="bargainph" date="1245306654"]Do you know when to use result_array()?

Do you know how to use $this->session->userdata()?[/quote]

1. Please refer to my previous post about how you are storing session data in the method of your controller. hint: look at your controller. hint 2: multidimensional array.
[quote author="yudahebat" date="1245306448"]
Code:
$this->session->set_userdata(array('nama' => $this->input->post('nama'),'photo' => $this->input->post('photo'),'harga' => $this->input->post('harga'),'renttgl' => $this->input->post('renttgl'),'rettgl' => $this->input->post('rettgl')));
[/quote]
2. A very good example of how this works is the Cart class(Why don't you try to use that? Please don't ONLY copy and paste code.).
3. Have you looked into the link I posted above about result_array()?
#8

[eluser]yudahebat[/eluser]
where can I find cart class?
#9

[eluser]Dam1an[/eluser]
It's in SVN




Theme © iAndrew 2016 - Forum software by © MyBB