0

I am building a scheduling system for volunteers. The woman doing the scheduling would like to see what tutors are available during a specific date and time. She'd also like to see if they are already scheduled for another day.

  • My first thought was to find all the tutors that are available for the time slot ($sql2 below) and then do a while to display those results.
  • Within the "while" I wanted to fetch the already scheduled information but I get an sql error.

Since the second query could be a one to many relationship, I wasn't sure how to do this as one query.

$sql2 = "SELECT `availID`, tutor.tutorID, tutorLastName, tutorFirstName, subjectID FROM tutorAvail\n"
    . "INNER JOIN tutor USING (`tutorID`)\n"
    . "INNER JOIN tutorSubjects USING (`tutorID`)\n"
    . "WHERE `day` = ? AND `availEnd` >= ? and availStart <= ?\n"
    . "and tutorSubjects.subjectID=?";
    $tutors=$mysqli->prepare($sql2);
    $tutors->bind_param('sssi', $row[1], $row[4], $row[3],  $subID);
    $tutors->execute();
    $tutors->bind_result($availID, $tutorID, $tLName, $tFName, $subID);
        while ($tutors->fetch()){
            //get schedule for tutor)
            $message="";
            $sql3="Select day from masterSchedule where tutorID=%";
            $tutSched=$mysqli->prepare($sql3);
            $tutSched->bind_param('i',$tutorID);
            $tutSched->execute();
            $tutSched->bind_results($day);
            while($tutSchedule->fetch()){
                $message .=$day.', ';
             }




            ?>
      {page output removed for brevity)
<?php

}//end while tutormatch
mario
  • 144,265
  • 20
  • 237
  • 291
  • 1
    What error message do you get? Is it perhaps the `%` instead of a `?` placeholder? -- If your question is about combining the two queries (instead of the loop query), then add details of your table schemes. (There's probably a way to make an optional join.) – mario Sep 20 '15 at 20:05
  • Thank you for fixing the code. Please let me know what you did to format it correctly so I will know in the future. The error I get is :Fatal error: Call to a member function bind_param() on a non-object in /Library/WebServer/Documents/cristoTutors/admin/scheduleStudent.php on line 209 – Julie McManus Anderson Sep 24 '15 at 13:49
  • [`bind_param` failing](http://stackoverflow.com/questions/17768200/call-to-a-member-function-bind-param-on-a-non-object-mysqli) indicates an SQL error. Enable [`error_reporting`](http://php.net/error_reporting) and use [`mysqli->error`](http://php.net/mysqli.error) to find out why. -- The code editor allows formatting per `{ }` button. – mario Sep 25 '15 at 01:27
  • Mario, I get the following error: Prepare failed: (2014) Commands out of sync; you can't run this command now So I am back to can I not run a prepare statement within a loop? Thanks, – Julie McManus Anderson Sep 26 '15 at 15:23

0 Answers0