CodeIgniter Forums
Load a foreach statement on page load? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Load a foreach statement on page load? (/thread-38516.html)



Load a foreach statement on page load? - El Forum - 02-10-2011

[eluser]Unknown[/eluser]
Hi,

Im hopeful someone may know how to solve this (probably) simple issue im having.

I have a page with a form that enters data into a database table.Next to this form i have a foreach statement which displays the posts that have been entered using the form. (so a basic write and read)

When you initially go to the form page, the list of posts on the right does not load until data has been sent using the webform.

is there a way to load this piece of code everytime the page loads? So that you dont necessarily HAVE to use the form to display existing posts?

>
<?php if(isset($records)) : foreach($records as $row) : ?>
<h2 class="area_h">&lt;?php echo $row->name; ?&gt;</h2>
Deadline:&lt;?php echo $row->project_deadline; ?&gt;
<h3 class="a_h">&lt;?php echo anchor("site/delete/$row->id", 'Delete post'); ?&gt; </h3>
&lt;?php endforeach; ?&gt;

Thank you!


Load a foreach statement on page load? - El Forum - 02-10-2011

[eluser]Rok Biderman[/eluser]
Well, untill you put it out from if (isset... conditional that is unlikely to happen. Hope this was enough of a tip Wink


Load a foreach statement on page load? - El Forum - 02-10-2011

[eluser]Unknown[/eluser]
ITS BEEN SUCH A LONG DAY ALREADY Sad

Your tip made me realise the blazing error in my logic!

Many thanks, its all sorted!