Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Optimization on Nested Loop

$
0
0
I have some concerns on Nested loop with sub query for example i have a main query that states like this


$main_query = "select fname,lname,dept from employee AS e INNER JOIN dept AS d on d.emp_id = e.emp_id"

foreach($main_query as $val):

then adding some query loops like
$sub_query = select sum(users) as total from assignees where emp_id = {$val->emp_id}


echo $sub_query ? $sub_query->total : "0";


endforeach;

is this a bad habit? My fix for this was to create and array on all assignments then loading it once then on the forloop i just called the array and check if its equal then i'll get the data on it?

is this the best approach?

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>