如何从多个循环中获取值

My Problem To Solve

  1. Get the schedule of a particular press based on range of dates.

I have the front end piece which accepts the press type and date ranges. When I click on search my logic presents me this

Date - 1

Schedule

Date - 2

Schedule

Now my programming logic is

  1. Get all distict dates via this

$getDatesSQL = "SELECT distinct date FROM xxx.schedulemain where costcenter = '$costCenter' AND date between '$datef' AND '$datet' AND priority > '0' ";

  1. Iterate over each dates and get schedule

    for($i=0;$i<count($dates);$i++){
      $sqlGetCostCenters = "SELECT sm.notes,sm.priority,sm.id,jh.jobnumber,jh.customer,round(sum(sm.hours),1) as time,jh.description,jh.production,jh.division,jh.duedate,sm.componenetnumber,sm.date 
                          FROM xxx.jobheader as jh Left Join xxx.schedulemain as sm On jh.jobnumber = sm.jobnumber 
                          where sm.costcenter = '$costCenter' AND sm.date = '$dates[$i]' AND sm.priority > '0' 
                          Group By sm.costcenter,jh.jobnumber,jh.description,jh.production,jh.division,jh.duedate,sm.componenetnumber,sm.date,jh.customer,sm.id,sm.priority,sm.notes 
                          Order By sm.date ASC, sm.priority ASC";
    }
    

While iterating I also store total number of jobs for each particular date by doing the following

$totalJobs[] = count($jobNumber);

now when presenting the data I am facing an Issue.

Similar to fetching when presenting the data

  1. I iterate over each dates

    for($i=0;$i<count($dates);$i++){
    //Now to get the data for that date I do inner iteration
    
          for($k=0;$k<$totalJobs[$i];$k++) {
    
          }
    }
    

So when the inner iteration starts, the first loop is fine but the second time the loop should start from all the jobs that have already looped through during first iteration.

I am not getting how to do that. Can some one please help?

So sorry everyone if I confused with my question as it was a little harder to explain.

I have however found a solution. My solution was

  1. Having a flag variable set to 0 on page load.
  2. Setting loop $k = $flag variable
  3. Once the iteration ends, update $flag with last run $k value.

This way when $k = $flag runs the second time it will start with value + 1 from previous iteration.

Once again sorry about the confusion.