Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- mysql_select_db("cs8cc", $con);
- // this function replaces a bunch of code, so the actual "do a query" bit is minimal within the logic.
- // it also die's on MySQL error (syntax error, or no DB selected, or no connection avaialable)
- function do_query($sql)
- {
- $result = mysql_query($sql);
- if( $result )
- {
- $return = array();
- while($row = mysql_fetch_assoc($result))
- $return[] = $row;
- }
- else
- {
- die(mysql_error());
- }
- }
- // $sql = ("SELECT Project.ProjectID, Marker.ProjectID, Marker.Num, Marker.MarkerID From Project INNER JOIN Marker ON Project.ProjectID = Marker.ProjectID");
- // The project and marker arrays... storing the Project ID and Marker num (0 for marker 1 and 1 for marker 2)
- $project_markers = do_query("SELECT p.ProjectID, m.Num, m.MarkerID FROM Project p INNER JOIN Marker m ON m.ProjectID = p.ProjectID");
- //$sql4 = ("SELECT Timeslot.TimeslotID, Student.StudentID From Timeslot INNER JOIN Student");
- //The student and timeslot array... storing all Student IDs and Timeslots
- //$StudentConflict_array = array([$StudentID_array][$TimeslotID]);
- //!!!!!!!!!! this one was kinda FUBAR - it was doing an INNER join with no ON clause, so probably returned 0 results
- $student_conflicts = do_query("SELECT t.TimeslotID, s.StudentID FROM Timeslot t NATURAL JOIN Student s");
- //$sql3 = ("SELECT MarkerAva.TimeslotID, MarkerAva.MarkerID, MarkerAva.Ava From MarkerAva");
- //The marker and timeslot array... storing all Marker IDs and Timeslots
- //$MarkerConflict_array = array([$MarkerID][$TimeslotID]);
- $marker_conflicts = do_query("SELECT TimeslotID, MarkerID, Ava FROM MarkerAva");
- // $sql2 = ("SELECT StudentID From Student");
- //Works out for each student if they are avaiable on a certain timeslot
- $student_ids = do_query("SELECT StudentID FROM Student");
- // new method
- $student_module_timeslot_clash = do_query("SELECT m.ModuleID, t.TimeslotID, ta.StudentID FROM Module m INNER JOIN Timeslot t ON (m.Day = t.Date AND m.Time = t.Time) JOIN Module m ON ta.ModuleID = m.ModuleID");
- // $student_module_timeslot_clash now contains an array where each row has a ModuleID, TimeslotID, and StudentID
- /* OLD METHOD FOR REFERENCE
- // $sql6 = ("SELECT Module.ModuleID, Module.Day, Module.Time, Timeslot.TimeslotID, Timeslot.Date, Timeslot.Time From Module INNER JOIN Timeslot WHERE Module.Day = Timeslot.Date AND Module.Time = Timeslot.Time");
- $module_timeslot_clash = do_query("SELECT m.ModuleID, t.TimeslotID FROM Module m INNER JOIN Timeslot t ON (m.Day = t.Date AND m.Time = t.Time)");
- // $sql7 =("SELECT Takes.ModuleID, Takes.StudentID, Module.ModuleID From Takes INNER JOIN Module ON Takes.ModuleID = Module.ModuleID");
- $student_modules = do_query("SELECT ta.ModuleID, ta.StudentID, m.ModuleID FROM Takes ta INNER JOIN Module m ON ta.ModuleID = m.ModuleID");
- foreach($student_modules as $sm)
- {
- foreach($module_timeslot_clash as $mtc)
- {
- if ($sm['ModuleID'] == $mtc['ModuleID'])
- {
- }
- }
- }
- */
Add Comment
Please, Sign In to add comment