Jump to content

Need help guys.. Time Difference


cyrixware

Recommended Posts

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? 

Link to comment
https://forums.phpfreaks.com/topic/91199-need-help-guys-time-difference/
Share on other sites

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

 

:)

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.

<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.

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?

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

$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...

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.