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?
$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?