Mulitple SQLs or parse multple foreach

Hi Guys,

About to write a view that has numerous lists of models (in this case, ‘jobs’). Was toying with the idea of doing one SQL array of jobs that encompasses all active jobs and the view has numerous ‘foreach’ loop statements parsing thru this to create the 8 or so lists (ie active jobs for user 1, active jobs for user 2, etc, future jobs for user 1, future jobs for user 2, etc, overdue jobs for user 1, overdue jobs for user 2, etc etc)

So in controller,

$this->render('board', array('jobs'=>$jobs))

and parse multiple foreachs in view, or go the multiple SQL queries and do,

$this->render('board', array('actjobsusr1'=>$actjobsusr1, 'actjobsusr2'=>actjobsusr2, etc etc))

Curious on which is more efficient, and best practice…

Thx for your vauable input!


Database queries are slow.

On the other hand reading all the data occupies much memory… so it’s a decision between speed and memory consumption…

So, considering the total number of records in the 1 database query will be low (ie approx a few hundred at most), best approach would be 1 database query and do the foreachs, but also to do the foreachs in the controller to split into arrays to avoid logic in the view…


Edit: although I’m having troubles splitting $jobs into $jobs_tech1, $jobs_tech2, etc after I’ve done this;

// lists all jobs that are OPEN

$criteria=new CDbCriteria;