PHP Nested for-each loop


foreach($QRYS1 as $QRY1)
 foreach($QRYS2 as $QRY2)
   foreach($QRYS3 as $QRY3)
     foreach($QRYS4 as $QRY4)


The above style of code makes data processing very slow. Is there anyway I can make the processing fast?

I am getting the data doing joining and counting with multiple tables and its all ARRAY().


fetching table using for-each loop will slow down your page. You can try joining of tables and fetch those fields which you want.


$TotalCountofDepartmentforSelectedComp_id = Userlog::where('userlogs.company_id', '=', $comp_id)
    ->where_Between('userlogs.created_at', $startDate, $endDate)
    ->get(['userlogs.department_id', DB::raw('count(userlogs.user_id) as totaldepartmentcount')]);

$ProductListforSelectedComp_id = Product::join('userlogs', 'userlogs.product_id', '=', '')
    ->where('userlogs.company_id', '=', $comp_id)
    ->get(['', '']);

$TotalCountCompanyProductWiseinforSelectedComp_id = Product::join('userlogs', 'userlogs.product_id', '=', '')
    ->where('userlogs.company_id', '=', $comp_id)
    ->where_Between('userlogs.created_at', $startDate, $endDate)
    ->get(['', DB::raw('count(userlogs.user_id) as totalcompanyproductcountuserwise')]);

$DepartmentListsforSelectedComp_id = Department::where('company_id', '=', $comp_id)->get(
    ['', '']

$TotalCountCompanyDepartmentProductWiseinforSelectedComp_id = DB::query(
    'SELECT, T2.department_id,
            COALESCE(T2.totaldepartmentproductcountuserwise, 0) AS totaldepartmentproductcountuserwise
       FROM (
         SELECT DISTINCT FROM products
           INNER JOIN userlogs ON userlogs.product_id =
           WHERE company_id = ?
         ) AS T1
       LEFT JOIN (
         SELECT department_id, product_id, COUNT(*) AS totaldepartmentproductcountuserwise
           FROM userlogs
           WHERE company_id = ?
             AND created_at BETWEEN ? AND ?
           GROUP BY department_id, product_id
         ) AS T2 ON T2.product_id =',
    array($comp_id, $comp_id, $startDate, $endDate)); 

Need Your Help

Is there a list of AJAX JSF Libraries available?

ajax jsf user-interface components packages

I'm looking for an alternative to to get a better idea of what JSF libraries are out there and to avoid having to write my own grid/table components. Or are these 27 the best the ...

Discover WCF Rest Service from iOS5

ios wcf wcf-rest service-discovery

I am building an iOS app that should communicate with a WCF Rest Service. They both will be on the same local network. While testing a have hardcoded the IP of the service, but that wont work when it