Passing Info From One View to Another
Posted
by 01010011
on Stack Overflow
See other posts from Stack Overflow
or by 01010011
Published on 2010-04-27T13:56:35Z
Indexed on
2010/05/02
4:17 UTC
Read the original article
Hit count: 306
codeigniter
|php
EDIT 1. The results of a query from my database are displayed on my view page. Next to each unique result is a button:
// first_view.php
<?php echo form_open('controller/method'); ?>
<?php foreach($results_found as $item): ?>
<p><?php echo $item->name ?></p>
<p><?php form_submit('buy','Buy This'); ?></p>
When a user clicks on one of these buttons (lets say button 4), I would like to display the user's choice from the array onto another view.
I've tried using this:
// first_view.php
<?php echo $this->session->set_userdata('choice',$item); ?>
immediately before
// first_view.php
<?php echo form_close(); ?>
thinking that the user's final choice would be stored there so I can display it on another view like this:
// second_controller.php
$c = $this->session->userdata('choice');
// second_view.php
echo 'Your Choose: '. $c;
However, what actually displays is the last result displayed on first_view.php, not what the user choose.
My question is, if the user clicked on button 4, how do I get that particular choice displayed onto another view?
END OF EDIT1
ORIGINAL QUESTION
My view page (CodeIgniter) displays the contents of an array in the form of several links. If a user clicks on a link, I want the user to be taken to another view page (via a controller) that gives more information concerning that particular link (which is stored in that particular position in the array)
My question is, how do I access and display the contents of that particular location within the array on the second view file without getting a "Undefined variable error" on the second view?
Here is what I am trying to do in code form
// my_controller.php
$array_name['variable_name'];
$this->load->view('first_view.php');
// first_view.php
<?php foreach($variable_name as $vn): ?>
<?php echo anchor('controller_name' $vn->info ?> // if user clicks on 3rd link
<?php endforeach ?> // I want to beable to access
// index 2 of the array in the
// second view file so I can
// display more info
// second_view.php
<?php $vn[2]->info ?>
© Stack Overflow or respective owner