Welcome Guest, Not a member yet? Register   Sign In
Formatting database results
#5

[eluser]bigtony[/eluser]
[quote author="Madmartigan1" date="1253309327"]I have to say bigtony, I disagree with you. Imagine what a mess a view file would be that had to preform many different string functions on several fields per result.[/quote]
All you've done is move the "mess" out of the view and into somwwhere else.

Your code:
Code:
foreach($result as $row)
{
    $row['name']       = uc_words($row['name']);//example
    $row['comment']    = htmlentities($row['comment']);//example
    $data['my_data'][] = $row;
}

In the view instead:
Code:
<?php foreach($result->result() as $row): ?>
    <tr>
        <td>&lt;?php echo uc_words($row{'name']); ?&gt;</td>
        <td>&lt;?php echo htmlentities($row['comment']); ?&gt;</td>
    </tr>
&lt;?php endif; ?&gt;
Doesn't look any messier to me...


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



Theme © iAndrew 2016 - Forum software by © MyBB