CodeIgniter Forums
Simple way of dumping rows to view? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Simple way of dumping rows to view? (/showthread.php?tid=27837)



Simple way of dumping rows to view? - El Forum - 02-22-2010

[eluser]goldpelican[/eluser]
Been using CodeIgniter for about 24 hours... so forgive me if this is a stupid question.

Been following the excellent CodeIgniter From Scratch screencasts by Jeffrey Way, and following his example, have created a controller + model + view that allows me to retrieve data from my database using Active Rows, and loop through them in the view. Now this is where it's a bit tedious... I want to display the entire row of data, not just a single field - and there's 13 fields in my table. Currently the code in the view looks like:

Code:
<?php foreach($records as $row) : ?>
    <?php echo $row->title; ?>
<?php endforeach; ?>

...which gives me the "title" field value... but is there a helper etc that will quickly dump out the entire row's values without having to do something like:

Code:
<?php foreach($records as $row) : ?>
    <?php echo $row->title; ?>, <?php echo $row->author; ?>, <?php echo $row->etc; ?>
<?php endforeach; ?>

I'm very much in prototype stage, and for now I just need to dump entire rows of data into views as I build up the framework of my application.

thanks!


Simple way of dumping rows to view? - El Forum - 02-22-2010

[eluser]rogierb[/eluser]
There is no helper to my knowlegde but if you use result_array() instead of result(), you can do an extra foreach to print out all the field.


Simple way of dumping rows to view? - El Forum - 02-22-2010

[eluser]codeshadow[/eluser]
Hey there,

The simplest way that I can think of is using
Quote:print_r()
(I don't know any helper either %-P ). However, you will still have to use the for construct. But would be as simple as this,

Quote:for($i=0;$i<sizeof($arr);$i++)
print_r($arr[$i]);

print_r($arr) will simply dump your array on the screen.


Simple way of dumping rows to view? - El Forum - 02-22-2010

[eluser]bretticus[/eluser]
Welcome to CodeIgniter!

This may or may not be flexible enough for you, but you can pretty much just dump an Active Record query to the table class to view it. See the manual.