[eluser]Jbeasley6651[/eluser]
I like being as efficient as possible, and i'm trying to apply these principles in my programming.
I have a page with lets say 5 different tables, each table shows results based on an If statement in a foreach loop
example of table showing result for cat-> == 1
Code:
<div id="dashA" class="column">
<?php foreach($dash->result() as $row) :?>
<?php if ($row->cat == 1) : ?>
<div id="port_<?=$row->id?>" class="portlet">
<div class="portlet-header"><?=$row->name?></div>
<? endif;?>
<?php endforeach; ?>
example of table showing result for cat-> == 2
Code:
<div id="dashB" class="column">
<?php foreach($dash->result() as $row) :?>
<?php if ($row->cat == 2) : ?>
<div id="port_<?=$row->id?>" class="portlet">
<div class="portlet-header"><?=$row->name?></div>
<? endif;?>
<?php endforeach; ?>
I'm only showing 2 above, pretend i'm showing 5 for the example below
Now, lets say i have 100 database rows in $dash, and i'm having to run this loop 5 times. Doesn't that seem like overkill?
So here's my question
Can't i just loop though once and use an array to do my if statements on?
How would i do this and would i do this in the controller? I'm not currently using models.
And if you were wondering, i do NOT want to run separate queries to return different sets of data.
Help would be appreciated.
Thanks,
JBeasley