cyrixware Posted February 15, 2008 Share Posted February 15, 2008 i have a problem regarding on my scheduling... let say for example i have here the room1 and room2.. every student has its own sched. Classes: Rm1 8:00 to 10:00 then after i saved this in my database.. Wen i try to insert a new schedule again for the Rm1 when i choose Rm1 9:00 to 10:00 it will display conflict schedule. how to do that? Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted February 15, 2008 Share Posted February 15, 2008 Can we see the code? Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 15, 2008 Author Share Posted February 15, 2008 not yet finish sir.... But sir can you give me some tips/hints about this. That when the existing time that are stored in the database will not conflict to the new time. ex. Correct Rm1 8:00am to 10:00am Rm1 10:00am to 11:00am Conflict Rm1 8:00am to 10:00am Rm1 9:00am to 11:00am Quote Link to comment Share on other sites More sharing options...
mem0ri Posted February 15, 2008 Share Posted February 15, 2008 It really depends on how you have your data organized. Are you keeping timestamps? Are you databasing each hour? How are you storing your data? Once we know how you are storing it, we'll be able to more easily tell you how to compare the datablocks to check for overlap. Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 15, 2008 Author Share Posted February 15, 2008 <form name="form" method="post" action="insert.php"> <select name="startTime"> <option>8:00</option> <option>9:00</option> <option>10:00</option> <option>11:00</option> <option>12:00</option> </select> <select name="endTime"> <option>8:00</option> <option>9:00</option> <option>10:00</option> <option>11:00</option> <option>12:00</option> </select> <input type="submit" name="Submit" value="Submit"> <? $conn = mysql_connect("localhost","root","") or die(mysql_error()); $db = mysql_select_db("compare") or die(mysql_error()); if($_REQUEST['Submit'] == "Submit"){ $startTime = $_REQUEST['startTime']; $endTime = $_REQUEST['endTime']; $sql_add = "INSERT INTO time ( fldSTime, fldETime ) VALUES ('$startTime', '$endTime')"; $q_add = mysql_query($sql_add); if(mysql_affected_rows() == 0){ echo "Cannot Save Record at this time try again later..."; }else{ echo" Sucessfully Save!"; } } ?> </form> Supposing i have two combo boxes which is.. the user will select the start time of the class and tha last one is for the end time of the class. How to trap or display a message if the schedule is conflict? Let say rm1 8-10am, rm1 9-10am which is conflict. thanks in advance. Quote Link to comment Share on other sites More sharing options...
mem0ri Posted February 15, 2008 Share Posted February 15, 2008 How about something like $query = "SELECT id FROM time WHERE (fldETime > '$startTime' AND fldETime < '$endTime') OR (fldSTime < '$endTime' AND fldSTime > '$startTime')"; It's not a query I've tried...but I don't see why it wouldn't work. Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 15, 2008 Author Share Posted February 15, 2008 Im going to insert this one...? $sql = "SELECT * FROM saveitem WHERE (studAnswer > '$startTime' AND studAnswer < '$endTime')"; if(!$q_class_list = mysql_query($sql)) { echo"Cannot Save!"; }else{ insert time in database codes.......... } Something like this? Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 15, 2008 Author Share Posted February 15, 2008 So, what im going to do is locate first in the database if the time exist... if and only if the time do not exist thats the time to insert/save? Am i correct? Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 16, 2008 Author Share Posted February 16, 2008 Hi any suggestions please Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted February 16, 2008 Share Posted February 16, 2008 Hello, Well depending on how you're storing your time as data, you can as easily check if the time is between two intervals right? Ken Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 16, 2008 Author Share Posted February 16, 2008 YEp So i have here 2 fields in my database the first one is the fldSTime and the other fldETime. The fldSTime is the begining hour or the time were the class start and the fldETime the end time of the class. Then what im trying to do is in the insert.php let say MATH Subject will start 8:00 to 9:00am then after i saved this one when i try to insert another sched again let say for example HISTORY Subject 9:00 to 10:00 the message dsplay is "Time Conflict!" (Consider the first code i posted above) So how to modify my source codes in order to perform the correct results? Regards Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 16, 2008 Author Share Posted February 16, 2008 $sql = "SELECT * FROM saveitem WHERE (fldSTime = '$startTime' AND fldETime <= '$endTime')"; if(!$q_class_list = mysql_query($sql)) { echo"Cannot Save!"; }else{ insert time in database codes.......... } I got this one... the only problem is wen i add an hour between the exsting time it still save. ex. CORRECT 8 to 10am 8 to 9am 8 to 12nn Msg = "CONFLICT SCHED!" ERROR 8 to 10am 9 to 10am Msg = "SAVE!" By the way thanks for the tips... Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 16, 2008 Author Share Posted February 16, 2008 I guess the solution is in the start time.... fldSTime = '$startTime'.. maybe the key answer is i this line... huhhhhhhhhhhhhh.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.