Welcome Guest, Not a member yet? Register   Sign In
while loop slows performance down - online
#7

[eluser]xwero[/eluser]
No there is no performance benefit and i don't think this should go in the query for two reasons

- if you want to use that model method again for other adding a RAND function based pseudo field to the result.

- The RAND function in mysql only capable of setting a maximum. the minimum is always zero

But if you do use the model method only for that page i would recommend you do add the random number to the model but also output the result instead of the query.
Code:
function somemethod()
{
    $rows = $this->db->get('table')->result();
    foreach($rows as $row)
    {
       $row->random = mt_rand(1,6);
    }
    return $rows;
}
This way the view doesn't know where the content comes from what makes it easier to reuse it.


Messages In This Thread
while loop slows performance down - online - by El Forum - 07-09-2008, 03:37 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 03:57 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 04:12 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 05:16 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 05:43 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 07:13 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 07:26 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 07:30 AM
while loop slows performance down - online - by El Forum - 07-09-2008, 07:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB