Welcome Guest, Not a member yet? Register   Sign In
How to loop through userdata?
#1

(This post was last modified: 01-24-2015, 05:48 PM by user2374.)

I have a form that once submitted, I am using to create an array of information that is used to fill a table on a results page. The validate function of the form puts all the info for the table into an array, which is saved as session userdata. Now I want to create a loop in my view page to fill a table with the saved user data. The elements in $query_array in my controller are stored in the order that I will be inserting them into the table. I can access any individual element of the array by using

PHP Code:
<?= $this->session->userdata['1']; ?>

but I cannot figure out how to replace '1' with the index of my for loop (ie, $j) on my view page. See code below:

PHP Code:
<tr>
 
               <td><?= $this->session->userdata['16']; ?> </td>
                <td class="txtcenter"><?= $this->session->userdata['17']; ?></td>
                <td class="txtcenter"><?= ucwords(str_replace('_'' '$this->session->userdata['query_state'])); ?></td>
                <td class="txtcenter"><img src="{site_url}assets/images/checklist.png" alt="checklist"  /></td>
 <td class="txtcenter"><?= $this->session->userdata['18']; ?>-***-****</td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
              </tr>
  
 <?php for($j 0$j $this->session->userdata['0']; $j++)
 
 { 
?>
 
 <tr>
                <td><?= $this->session->userdata['query_fullname7']; ?> </td>
                <td class="txtcenter"><?= $this->session->userdata['query_agerange3']; ?></td>
                <td class="txtcenter"><?= ucwords(str_replace('_'' '$this->session->userdata['query_state'])); ?></td>
                <td class="txtcenter"><img src="{site_url}assets/images/checklist.png" alt="subscriber benefits checklist"  /></td>
 <td class="txtcenter"><?= $this->session->userdata['query_phone3']; ?>-***-****</td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
 <td class="txtcenter"></td>
              </tr>
  
  <?php ?>
  
  </tbody>
 </table> 

Note that the first row in the table, before the for loop, is just there to show how I am retrieving individual array elements. The for loop is after the first row, and the 'query_fullname7' type array elements within the loop are old, needing to be replaced by the array index ($j).

And here's the relevant code from my controller containing the array stored in userdata:

PHP Code:
$query_array = array(
 
 
'0' => $numberofrows,
 
 
'1' => $this->input->post('fname'),
 
'2' => $this->input->post('lname'), 
 
'3' => $this->_agegenerator($originalage),
 
'4' => $this->input->post('state'),
 
'5' => $this->_statephone($this->input->post('state')),

 
'6' => $this->input->post('fname'),
 
'7' => $this->input->post('lname'),
 
'8' => $this->_agegenerator($originalage),
 
'9' => $this->_statephone($this->input->post('state')),
 
 
'10' => $this->_createnames($tempfname$templname), 
 
'11' => $this->_agegenerator($originalage),
 
'12' => $this->_statephone($this->input->post('state')),
 
 
'13' => $this->_createnames($tempfname$templname), 
 
'14' => $this->_agegenerator($originalage),
 
'15' => $this->_statephone($this->input->post('state')),
 
 
'16' => $this->_createnames($tempfname$templname), 
 
'17' => $this->_agegenerator($originalage),
 
'18' => $this->_statephone($this->input->post('state')), 
 
 
'19' => $this->_createnames($tempfname$templname), 
 
'20' => $this->_agegenerator($originalage),
 
'21' => $this->_statephone($this->input->post('state')) 
 
 
 );
 
           $this->session->set_userdata($query_array);
 
           $this->session->set_flashdata('type'$searchtype);
 
 
redirect('/search/results''refresh'); 


I have tried the following to loop through the userdata:

PHP Code:
<?= $this->session->userdata[$j]; ?>
PHP Code:
<?= $this->session->userdata['$j']; ?>

What do I need to do to make this work?
Reply


Messages In This Thread
How to loop through userdata? - by user2374 - 01-24-2015, 04:57 PM
RE: How to loop through userdata? - by RobertSF - 01-24-2015, 11:01 PM
RE: How to loop through userdata? - by stopz - 01-26-2015, 04:26 AM
RE: How to loop through userdata? - by user2374 - 01-26-2015, 08:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB