Page 2 of 2

Re: Time comparisons

Posted: Mon Jan 26, 2009 6:17 pm
by VladSun
You may use it in the very same way as Mark's code - i.e. it's for PHP layer, not the DB one.
If you elaborate the details of your problem, including the DB design probably we can help you to build it in DB layer.

Re: Time comparisons

Posted: Mon Jan 26, 2009 6:29 pm
by juxp00
Thank you

I have it working as a PHP layer from Mark's example - ie I can select $starttime from my DB and assign a time zone correctly based on this.

I am also trying to assign the time zone, on upload of a form.

My process file is doing this:

Code: Select all

 
<?php
include('../includes/dbconnect.php');
 
$error = false;
 
if (isset($_POST['addevent'])) {
 
$hostcompany = $_POST['hostcompany'];
$type = $_POST['type'];
$custom_event = $_POST['custom_event'];
$eventtitle = $_POST['eventtitle'];
$date = $_POST['date'];
$predate = $_POST['predate'];
$starttime = $_POST['starttime'];
$endtime = $_POST['endtime'];
$venue = $_POST['venue'];
$description = $_POST['description'];        
$invite = $_POST['invite'];
$dateadded = $_POST['dateadded'];
$status = $_POST['status'];
$username = $_POST['username'];
$company = $_POST['company'];
 
$abc = strtotime($row['starttime']);
$hour = date("G:i",$abc);
$timezone = 0;
if (($hour >= 6) && ($hour < 12)) {
   $timezone = 1;
} elseif (($hour >= 12) && ($hour < 17)) {
   $timezone = 2;
} elseif ($hour >= 17) {
   $timezone = 3;
}
 
$query = "INSERT INTO events (hostcompany,type,custom_event,eventtitle,date,predate,starttime,endtime,venue,description,invite,dateadded,status,username,company,timezone) VALUES ('".$hostcompany."','".$type."','".$custom_event."','".$eventtitle."','".$date."','".$predate."','".$starttime."','".$endtime."','".$venue."','".$description."','".$invite."','".$dateadded."','".$status."','".$username."','".$company."','".$timezone."')";
 
$result = mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
Header("Location: /users/addevent.php?mesg=Event added sucessfully, thank you.");
exit;
}
else {
$error = true; // input validation failed
}
 
?>
However, when I try to assign the timezone in this way, I only get timezone of 3 input into my "timezone" field.

That's where I;m at - its working, but not on form upload to DB, so any pointers would be much appreciated.

Thanks a lot

Re: Time comparisons

Posted: Mon Jan 26, 2009 6:35 pm
by juxp00
DB set up is as such:

Code: Select all

 
`event_id` smallint(4) unsigned NOT NULL auto_increment,
  `hostcompany` varchar(250) NOT NULL,
  `type` varchar(250) NOT NULL,
  `custom_event` varchar(255) NOT NULL,
  `eventtitle` varchar(250) NOT NULL,
  `date` varchar(255) NOT NULL,
  `predate` varchar(255) NOT NULL,
  `starttime` time default NULL,
  `endtime` time NOT NULL,
  `venue` varchar(250) NOT NULL,
  `description` varchar(250) NOT NULL,
  `invite` varchar(255) NOT NULL,
  `dateadded` date NOT NULL,
  `status` char(1) NOT NULL default '0',
  `username` varchar(250) NOT NULL,
  `company` varchar(250) NOT NULL,
  `timezone` varchar(250) NOT NULL,
  PRIMARY KEY  (`event_id`)