Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <?
  2. mysql_select_db("cs8cc", $con);
  3.  
  4. // this function replaces a bunch of code, so the actual "do a query" bit is minimal within the logic.
  5. // it also die's on MySQL error (syntax error, or no DB selected, or no connection avaialable)
  6. function do_query($sql)
  7. {
  8. $result = mysql_query($sql);
  9. if( $result )
  10. {
  11. $return = array();
  12. while($row = mysql_fetch_assoc($result))
  13. $return[] = $row;
  14. }
  15. else
  16. {
  17. die(mysql_error());
  18. }
  19. }
  20.  
  21. // $sql = ("SELECT Project.ProjectID, Marker.ProjectID, Marker.Num, Marker.MarkerID From Project INNER JOIN Marker ON Project.ProjectID = Marker.ProjectID");
  22. // The project and marker arrays... storing the Project ID and Marker num (0 for marker 1 and 1 for marker 2)
  23. $project_markers = do_query("SELECT p.ProjectID, m.Num, m.MarkerID FROM Project p INNER JOIN Marker m ON m.ProjectID = p.ProjectID");
  24.  
  25.  
  26. //$sql4 = ("SELECT Timeslot.TimeslotID, Student.StudentID From Timeslot INNER JOIN Student");
  27. //The student and timeslot array... storing all Student IDs and Timeslots
  28. //$StudentConflict_array = array([$StudentID_array][$TimeslotID]);
  29. //!!!!!!!!!! this one was kinda FUBAR - it was doing an INNER join with no ON clause, so probably returned 0 results
  30. $student_conflicts = do_query("SELECT t.TimeslotID, s.StudentID FROM Timeslot t NATURAL JOIN Student s");
  31.  
  32. //$sql3 = ("SELECT MarkerAva.TimeslotID, MarkerAva.MarkerID, MarkerAva.Ava From MarkerAva");
  33. //The marker and timeslot array... storing all Marker IDs and Timeslots
  34. //$MarkerConflict_array = array([$MarkerID][$TimeslotID]);
  35. $marker_conflicts = do_query("SELECT TimeslotID, MarkerID, Ava FROM MarkerAva");
  36.  
  37.  
  38. // $sql2 = ("SELECT StudentID From Student");
  39. //Works out for each student if they are avaiable on a certain timeslot
  40. $student_ids = do_query("SELECT StudentID FROM Student");
  41.  
  42.  
  43.  
  44. // new method
  45. $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");
  46. // $student_module_timeslot_clash now contains an array where each row has a ModuleID, TimeslotID, and StudentID
  47.  
  48.  
  49. /* OLD METHOD FOR REFERENCE
  50. // $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");
  51. $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)");
  52.  
  53.  
  54. // $sql7 =("SELECT Takes.ModuleID, Takes.StudentID, Module.ModuleID From Takes INNER JOIN Module ON Takes.ModuleID = Module.ModuleID");
  55. $student_modules = do_query("SELECT ta.ModuleID, ta.StudentID, m.ModuleID FROM Takes ta INNER JOIN Module m ON ta.ModuleID = m.ModuleID");
  56.  
  57.  
  58.  
  59. foreach($student_modules as $sm)
  60. {
  61. foreach($module_timeslot_clash as $mtc)
  62. {
  63. if ($sm['ModuleID'] == $mtc['ModuleID'])
  64. {
  65.  
  66. }
  67. }
  68. }
  69. */
Add Comment
Please, Sign In to add comment