How do you write a query that executes for each different result in a query? To explain, I run one query to find all the "punch_periods" within a date range:
$search_date = mysql_query("SELECT punch_period
FROM timecards
WHERE emp_id ='1' &&
punch_time BETWEEN '$start' AND '$end'
ORDER BY punch_time");
while($periods = mysql_fetch_array($search_date)) {
// run another query for each different punch_period
}
The result might be 1,1,1,1,2,2. Instead of running a second query 6 times (for each result), I need to run a second query 2 times (for each DIFFERENT punch_period). It will be something like:
$punches = mysql_query("SELECT * FROM timecards
WHERE emp_id ='1' &&
punch_period = [RESULT FROM 1ST QUERY]");
The reason I'm doing it this way is because I can't search by date alone- someone may clock in at 11:30pm one day and clock out at 1:00am the following "day". By searching by unique punch periods, I can get total hours worked in a "workday" even if it overlaps a true calendar "day".