I have a question on how to perform a nested loop based on some SQL data. I have a SQL query in which I'm looking for some records within a date range and ordered by a 'Trainer' field. I want to take that data and perform a count of certain fields for each trainer and put them in a table. I have the php code that finds me the records but I'm having trouble with the inside loop that would go through the records and perform a running count for each trainer. I'm not sure what I should use for the inside loop and what criteria I need to use with it. Do I use a while or a foreach or something else?
What I have so far is:
$CTOQuery = "SELECT * from Training where (Date between '" . $_REQUEST['StartDate'] . "' and '" . $_REQUEST['EndDate'] . "') order by CTO";
$CTOResult = sqlsrv_query($conn, $CTOQuery, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
while ($CTOrow = sqlsrv_fetch_array($CTOResult, SQLSRV_FETCH_ASSOC)) {
// Inside loop here
}
What I have so far is:
$CTOQuery = "SELECT * from Training where (Date between '" . $_REQUEST['StartDate'] . "' and '" . $_REQUEST['EndDate'] . "') order by CTO";
$CTOResult = sqlsrv_query($conn, $CTOQuery, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
while ($CTOrow = sqlsrv_fetch_array($CTOResult, SQLSRV_FETCH_ASSOC)) {
// Inside loop here
}