Check for Time/Date Conflict php
<p>I am currently developing a simple student scheduling application for a school enrollment. I have created two tables for subject schedule and reserve subject for the student. for schedule subject 1. subject code with Pk sched_id and for reserve subject code  FK subid, Day,labday, lecturetime, labtime. When a user select subject from schedule it will inserted to reservsub. I need the feature of checking for a day/labday time/labtime conflict for every subject that have been selected. For example:</p>

<p>User select subject with TTh  9:00am - to 11:00am day and lectime
And in reservetable it has  Thursday 10:30am - 12:30pm day and lectime</p>

<p>How do I build a script and/or function that would warn the user that it have a time conflict in php?</p>

<p>Thank you in advance.</p>

<p>here's the code for display the schedule and select</p>

<pre><code>$sql = mysql_query("SELECT * FROM tblsubjecschedule  where Sem='".$_SESSION['sem']."' and Schoolyear='".$_SESSION['Sy']."' order by Subject")or die(mysql_error());

        $i=0;
        $b =1;  
    while($row=mysql_fetch_assoc($sql) ){ 
                        echo "&lt;tr &gt;&lt;td align=' '&gt;&lt;input id='send' name='reserv[$i]' type='image' src='images/Select.gif' onclick='addRow('myTable')' /&gt; &lt;/td&gt;
                        &lt;td align=' '&gt;".$row['Subject']."&lt;input type='hidden' name='subj[$i]' value=".$row['Subject']."&gt;&lt;input type='hidden' name='control[$i]' value=".$row['sched_id']."&gt;&lt;/td&gt;
                          &lt;td align=' '&gt;".$row['section']."  &lt;/td&gt;
                        &lt;td align=' '&gt;".$row['Lec']."-".$row['Lab']."  &lt;/td&gt;

                        &lt;td align=' '&gt;".$row['Descriptive']." &lt;/td&gt;
                        &lt;td align=' '&gt;".$row['Day']."&lt;br/&gt;".$row['Labday']." &lt;/td&gt;

                        &lt;td align=' '&gt;".$row['LecTime']."&lt;br/&gt;".$row['LabTime']."  &lt;/td&gt;

                        &lt;td align=' '&gt;".$row['Room']."&lt;br/&gt;".$row['Labroom']." &lt;/td&gt;
                        &lt;td align=' '&gt;".$row['capacity']." &lt;/td&gt;
                        &lt;td &gt;".$row['Slot']." &lt;/td&gt;

                        &lt;/tr&gt;";

        $i++;


                        }


    if (isset($_POST['reserv'])){
            if(!empty($_POST['reserv'])){
                $a = current(array_keys($_POST['reserv']));
                                $control=$_POST['control'][$a];



                                        }

                        }
$sql = mysql_query("SELECT * FROM tblsubjecschedule  where sched_id='".$control."' and Sem='".$_SESSION['sem']."' and Schoolyear='".$_SESSION['Sy']."'");
                                            while($row=mysql_fetch_assoc($sql) ){
                                                    $cont=$row['sched_id'];
                                                    $sub=$row['Subject'];
                                                    $sec=$row['section'];
                                                    $lecture=$row['Lec'];
                                                    $laboratory=$row['Lab'];
                                                    $day=$row['Day'];
                                                    $daylab=$row['Labday'];
                                                    $lectime=$row['LecTime'];
                                                    $ltime=$row['LabTime'];
                                                    $room=$row['Room'];
                                                    $roomlab=$row['Labroom'];
                                                    $slot=$row['Slot'];
                                                    $caps=$row['capacity'];
                                            } 
</code></pre>

<p>When subject is selected the tblreserv will verify if the data its already been save or it has a time conflict </p>

<pre><code>    $verify2=mysql_query("Select * from tblsubjectreserv where stud_id='".$maxid."' and subject='".$sub."'")or die(mysql_error());                   
                        $ver=mysql_num_rows($verify2);
                            if($ver!=0){
                            echo '&lt;script language="javascript"&gt;alert("This Subject already exists.");&lt;/script&gt;';
                            }
                                else{ 


      $insert2=mysql_query("insert into tblsubjectreserv (sublink,stud_id,subject,section,Unitlec,Unitlab,timelec,timelab,daylec,Daylab,roomlec,roomlab,Sem,schoolyear)values('".$control."','".$maxid."','".$sub."','".$sec."','".$lecture."','".$laboratory."','".$lectime."','".$ltime."','".$day."','".$daylab."','".$room."','".$roomlab."','".$sem."','".$_SESSION['Sy']."')")or die(mysql_error());



}
</code></pre>

<p>but i dont know how to verify the day/time conflict.
im just a beginner please help me.</p>

<p>thank you in advance </p>
