Formatting database results

#1
[eluser]Madmartigan1[/eluser]
What's the best way to format database results before they are sent to the view file?

I'd rather not be writing php functions like strtolower() trim() and htmlspecialchars() into the view file - it makes a big mess. I can't seem to figure out how to do this for multiple database results using the active record class. It seems like it could be done in the model, but should be done in the controller.

I'd like to be able to use the parser class, which requires result_array() for database query results. It would be great if my boss, who knows nothing about php, could edit my view files without screwing them up.

This seems to work ok...

Code:
$query=$this->db->get('my_table');
$result=$query->result_array();
foreach($result as $row)
{
    $row['name']       = uc_words($row['name']);//example
    $row['comment']    = htmlentities($row['comment']);//example
    $data['my_data'][] = $row;
}
$this->parser->parse("my_view",$data);

Am I doing it right? :-S

Any help would be greatly appreciated, thanks!


Messages In This Thread
Formatting database results - by El Forum - 09-17-2009, 11:32 PM
Formatting database results - by El Forum - 09-18-2009, 01:52 AM
Formatting database results - by El Forum - 09-18-2009, 10:28 AM
Formatting database results - by El Forum - 09-18-2009, 07:43 PM
Formatting database results - by El Forum - 09-19-2009, 12:12 AM
Formatting database results - by El Forum - 09-19-2009, 04:54 AM
Formatting database results - by El Forum - 09-19-2009, 12:30 PM
Formatting database results - by El Forum - 09-19-2009, 02:02 PM
Formatting database results - by El Forum - 09-19-2009, 02:14 PM
Formatting database results - by El Forum - 09-19-2009, 10:16 PM
Formatting database results - by El Forum - 09-29-2009, 02:53 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.