CodeIgniter Forums
Listing DB entries? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Listing DB entries? (/showthread.php?tid=56540)



Listing DB entries? - El Forum - 12-29-2012

[eluser]Unknown[/eluser]
Hi everybody,

I started using CI and I'm having a problem with database entry listing.
I list the entries fine, but I need to assign some template to them.

For instance

Code:
<div class="class">$title</div>
<div class="class">$date</div>

Function for DB listing is as follows:
Code:
$query = $this->db->get('posts', 10);
        foreach($query->result() as $row) {
  $data[] = $row;
  }
  return $data;

Now, if I echo the template in foreach loop, I'll most likely get some kind of error, since I noticed CI is really strict about output, but I have no idea, even if that works, how to send it to the view.


Listing DB entries? - El Forum - 12-29-2012

[eluser]Unknown[/eluser]
Solution: Instead of outputting an array of data, output just one variable that contains the design.
Although it solves a template problem, it doesn't solve a problem of outputting only one result.

So, the question is: How to output more results?


Listing DB entries? - El Forum - 12-29-2012

[eluser]sajid19991[/eluser]
[quote author="stefo" date="1356810398"]Solution: Instead of outputting an array of data, output just one variable that contains the design.
Although it solves a template problem, it doesn't solve a problem of outputting only one result.

So, the question is: How to output more results?[/quote]

Hi, if you are new i would suggest you to output the result using codeigniters template parser library, which will solve most of your problems. please refer to CI Template Parser Guide ...i always use parser for better results with design..its not advanced parser but advance enough to get rid of some headaches...