Hi forsooth, here is the final code that I used. I adapted the queries a little to reduce the load on the db. Also, added the checking for weekends as I didn't want it to return FALSE if the day was a weekend only week day.
As a side note - this is part of a codeignitor development I'm working on - thus the $this->db type calls.
// Gets consecutative dates for drop down box. -- need to work on weekends.
// -- needs rewriting to activerecord queries
function get_date_block($sid, $start_date) {
$continue = TRUE;
// Start final SQL query
$sql = "SELECT DISTINCT AttDateTime FROM oasys_vw_master WHERE StuRef = '$sid' AND (AttDateTime = '$start_date'";
// Work out other dates needed
while ($continue == TRUE) {
$start_date = date("Y-m-d", strtotime($start_date . "+1 day"));
// Needs rewriting as ActiveRecord
$query = $this->db->query("SELECT StuRef FROM oasys_vw_master WHERE StuRef = '$sid' AND AttMark IN ('O', 'L', 'B', 'R') AND AttDateTime = '$start_date'");
if ($query->num_rows() > 0) {
$sql .= " OR AttDateTime = '$start_date'";
} else {
// If day is Saturday or Sunday don't stop script.
if (date('N', strtotime($start_date)) < '5') {
$continue = FALSE;
}
}
}
// End final query SQL
$sql .= ") ORDER BY AttDateTime";
// Now query database to select dates for drop down box
$query = $this->db->query($sql);
return $query->result();
}