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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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