Jump to content

Create error message in comparing date, room in a calendar


dsp77

Recommended Posts

i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same date, time and room without receiving any error i don't know where to start to compare the days hours with location (the 2 different tables are confusing me). To explain better i have like this:

Table1 with: Start Date, End Date, Start Hour, End Hour and other things not important for validation

Table2 with: Room1, Room2, Room3 etc

 

What MYSQL syntax to use or what code i'm brain dead now i don't know from where to start, at least someone can tell me the logic from where to start.

Hi,

 

Below is untested but should give some basic logic. just want to see if there is an appointment with a start time between your new appointments start and end time.

 


<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$dbname = 'database';
mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to mysql");
mysql_select_db($dbname);

$startDate =  "";
$startTime =  "";
$endDate =  "";
$endTime =  "";
$room =  "";

$query = "SELECT * FROM Table1 WHERE table='".table."' AND startDate='".$startDate."' AND startTime BETWEEN '".$startTime."' AND '".$endTime."'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0){
    //an appointment already in that timeframe.
}
?>

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.