tourer Posted December 4, 2009 Share Posted December 4, 2009 hey friends . I have written a code where i want to compare the Server Current Time & Date with the Start_date, starttime & endtime fetched from the database. but i am finding some trouble with the sql query. The sql query for the field resid is working, but its not fetching start_date, starttime & endtime. the resid is entered by the user which is compared withe one in datebase. Aftere which the Start_date & Current date are compared on the backend. The Start_date is stored in a Unix timestamp format. such as for yesterday, it shows 1259778600 as date. and start & end time are converted in minutes, i:e: for 3.00 pm it shows 900 in the DB. Can anyone please help me out of this: <?php date_default_timezone_set('Asia/Kolkata'); $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'labview'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'phpscheduleit'; mysql_select_db($dbname,$conn) or die ("could not open db".mysql_error()); //$start_date = 1259865000; //$starttime = 900; //$endtime = 960; // Make timestamp for today's date $dv = array(); $today = getdate(); $dv['month'] = $today['mon']; $dv['day'] = $today['mday']; $dv['year'] = $today['year']; $default = true; $dv['todayTs'] = mktime(0,0,0, $dv['month'], $dv['day'], $dv['year']); $Tdate = date('H') * 60 + date('i'); $userId = $_POST['resid1']; $sql = "SELECT resid, start_date, starttime, endtime FROM reservations WHERE resid = '$userId'"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result)) { if ($dv['todayTs'] == "$start_date"){ if($Tdate >= "$starttime" && $Tdate < "$endtime") { echo "www.localhost/e1.html(user should navigate to this page)"; } else { echo "This is not your time slot"; }}else { echo "Your slot is booked for some other day"; }}else{ echo "Wrong Reservation id"; } ?> Link to comment https://forums.phpfreaks.com/topic/183962-comparision-in-php/ Share on other sites More sharing options...
MadTechie Posted December 4, 2009 Share Posted December 4, 2009 Well the first thing I would do, would be fetch from the database, as your not pulling out the data <?php date_default_timezone_set('Asia/Kolkata'); $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'labview'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'phpscheduleit'; mysql_select_db($dbname,$conn) or die ("could not open db".mysql_error()); //$start_date = 1259865000; //$starttime = 900; //$endtime = 960; // Make timestamp for today's date $dv = array(); $today = getdate(); $dv['month'] = $today['mon']; $dv['day'] = $today['mday']; $dv['year'] = $today['year']; $default = true; $dv['todayTs'] = mktime(0,0,0, $dv['month'], $dv['day'], $dv['year']); $Tdate = date('H') * 60 + date('i'); $userId = $_POST['resid1']; $sql = "SELECT resid, start_date, starttime, endtime FROM reservations WHERE resid = '$userId'"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); //Fetch Data and use $row to get fields data if ($dv['todayTs'] == $row['start_date']){ if($Tdate >= $row['starttime'] && $Tdate < $row['endtime']) { echo "www.localhost/e1.html(user should navigate to this page)"; } else { echo "This is not your time slot"; } }else { echo "Your slot is booked for some other day"; } }else{ echo "Wrong Reservation id"; } ?> Link to comment https://forums.phpfreaks.com/topic/183962-comparision-in-php/#findComment-971119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.