I want to create a function that select the begin date and end date and then insert into the database. I want to insert the date for every 4 days from 30/8 til 30/9 to the database...
For example:
table
row 1 = 30/8
row 2 = 3/9
row 3 = 7/9
row 4 = 11/9 ... and so on
My php:
<?php
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("test", $con);
$start_date= "2015-08-30";
$end_date= "2015-09-30";
$insert = "INSERT INTO calendar(date)......";
if(mysql_query($insert,$con)) {
echo "<script> alert('Insert Successful'); </script>";
}
else {
echo "<script> alert('Insert Unsuccessful'); </script>";
}
while (strtotime($start_date) <= strtotime($end_date)) {
//echo "$start_date <br>";
$start_date = date ("Y-m-d", strtotime("+4 day", strtotime($start_date)));
}
Think this is what your searching for... let me know anything needed to change...
<?php
$start_date= "2015-08-30";
$end_date= "2015-09-30";
$inc_val = 4;
$start_con_to_time = strtotime($start_date);
$end_con_to_time = strtotime($end_date);
$days_between = ceil(abs($end_con_to_time - $start_con_to_time) / 86400);
for($x=$inc_val+1; $x<=$days_between;)
{
echo date('Y-m-d', strtotime($start_date. ' + ' . $x . 'days'));
echo ' : Add database code here <br>';
$x+=$inc_val;
}
?>
Related
I have a PHP loop which draws a table based off a MYSQLi query.
What i would like to do is create this table based on a userid (in my case the column called 'badgeid')
At the moment its creating one table
$sql = "SELECT first_name,last_name,signintime,signouttime FROM `signin_entries` WHERE iscleaner ='YES' AND signindate = curdate()";
$list_visitors_result=mysqli_query($con,$sql);
$count_visitors = mysqli_num_rows($list_visitors_result);
if($count_visitors != 0) {
while($row = mysqli_fetch_array($list_visitors_result)){
$signintime = $row['signintime'];
$signouttime = $row['signouttime'];
$firstname = $row['first_name'];
$lastname = $row['last_name'];
echo " <tr><td>$firstname $lastname</td>
<td>$signintime</td>";
if ($signouttime == ""){
echo "<td>Not Signed Out Yet</td>";
} else {
echo "<td>$signouttime</td>";
}
$timeFirst = strtotime(date("Y/m/d") . " " . $signintime);
$timeSecond = strtotime(date("Y/m/d") ." " . $signouttime);
//below checks if th second time is less than the first time than it must be from the day before so add 24 hours eg (signin time 23:30:00 signout time 07:30:30 would be 08:00:30 difference)
if ($timeSecond < $timeFirst)
{
$timeSecond = $timeSecond + 86400;
}
if ($signouttime == ""){
echo "<td>Cleaner Has Not Signed Out Yet</td>";
} else {
$differenceInSeconds = $timeSecond - $timeFirst;
echo "<td class='rowDataSd'>".converttime($differenceInSeconds)."</td>";
}
echo "</tr>";
}
}
//below function converts the seconds difference into hh:mm:ss format to the nearest second
function converttime($seconds) {
$t = round($seconds);
return sprintf('%02d:%02d:%02d', ($t/3600),($t/60%60), $t%60);
}
echo "<tr><th></th><th></th><th></th><th>Total Time Worked</th><tr><td></td><td></td><td></td><td class='totalCol'>Total:</td></tr>";
?>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
Which is great but i really need a table per 'badgeid'
You could do it like that:
$sql = "SELECT first_name,last_name,signintime,signouttime FROM `signin_entries` WHERE iscleaner ='YES' AND signindate = curdate() ORDER BY badgeid ASC";
$list_visitors_result=mysqli_query($con, $sql);
$count_visitors = mysqli_num_rows($list_visitors_result);
if ($count_visitors != 0) {
echo '<table>';
$current_badgeid = '';
while ($row = mysqli_fetch_array($list_visitors_result)) {
if ($current_badgeid == '') {
$current_badgeid = $row['badgeid']; //define if empty, for the first table
}
if($row['badgeid'] != $current_badgeid){
echo '</table><table>';
$current_badgeid = $row['badgeid'];
}
$signintime = $row['signintime'];
$signouttime = $row['signouttime'];
$firstname = $row['first_name'];
$lastname = $row['last_name'];
echo " <tr><td>$firstname $lastname</td><td>$signintime</td>";
if ($signouttime == "") {
echo "<td>Not Signed Out Yet</td>";
} else {
echo "<td>$signouttime</td>";
}
$timeFirst = strtotime(date("Y/m/d") . " " . $signintime);
$timeSecond = strtotime(date("Y/m/d") ." " . $signouttime);
//below checks if th second time is less than the first time than it must be from the day before so add 24 hours eg (signin time 23:30:00 signout time 07:30:30 would be 08:00:30 difference)
if ($timeSecond < $timeFirst) {
$timeSecond = $timeSecond + 86400;
}
if ($signouttime == "") {
echo "<td>Cleaner Has Not Signed Out Yet</td>";
} else {
$differenceInSeconds = $timeSecond - $timeFirst;
echo "<td class='rowDataSd'>".converttime($differenceInSeconds)."</td>";
}
echo "</tr>";
}
echo '</table>';
}
First, you add ORDER BY badgeid ASC to your query. Then you open a table before the loop starts, and you define a $current_badgeid var. Each time the badgeid changes, you close and reopen a table.
I am needing to find the next 30 days and put in array to repeat a scheduling code.
So I would need to have a variable for
$date= "would hold the date";
$day_of_week= "would hold the # value for the day of week";
I am at a loss of where to even start... I am wanting to repeat the following code for each respective day to schedule crews for the next 30 days.
<?
// Connection Script
include 'connection.php';
date_default_timezone_set("America/New_York");
$tomorrow= strtotime('+ 1 day');
$date= date('N', $tomorrow);
// Get all employees who work tomorrow and group by unit//
$units= "select e.user_id, e.station, e.full_name, max(e.level) level, es.unit, es.days, es.start_time, es.end_time from employees e
left join employee_schedule es on es.pid = e.user_id
where es.days like '%$date%' and e.status = 1
group by es.unit";
$units_result= $conn->query($units);
//Roll through all employees who work tomorrow and place then in appropriate unit.
while($row_unit = $units_result->fetch_assoc()) {
if($row_unit['level'] == 3){
$level= 1;
}elseif($row_unit['level'] == 4){
$level= 2;
}elseif($row_unit['level'] == 5){
$level= 3;
}elseif($row_unit['level'] == 8){
$level= 4;
}
//Get Unit ID from each group
$unitid = $row_unit['unit'];
$intime= date('Y-m-d', $tomorrow);
$intime= $intime.' '. $row_unit['start_time'];
$length= '+ 23 hours';
$intimes= strtotime("$intime");
$endtime= strtotime("$length","$intimes" );
$endtime= date('Y-m-d H:i:s', $endtime);
$station= $row_unit['station'];
$timenow= date('Y-m-d H:i:s');
echo "<p>I am scheduling unit number $unitid to be on at $intime and leave at $endtime </p>";
$unitinsert= "insert into schedules (date_time, unit, level_of_service, start_time, end_time, station)
values ('$timenow', $unitid, $level , '$intime', '$endtime', $station)";
if(mysqli_query($conn, $unitinsert)){
echo "Records inserted successfully.";
$unitinid= $conn->insert_id;
echo $unitinid;
} else{
echo "ERROR: Could not able to execute $unitinsert. " . mysqli_error($conn);
}
$employee = "select e.*, es.unit, es.days, pc.email as pemail from employees e
left join employee_schedule es on es.pid = e.user_id
left join phone_carriers pc on pc.id = e.phone_carrier
where es.days like '%$date%'and es.unit = $unitid and e.status = 1";
$employee_result= $conn->query($employee);
if(mysqli_num_rows($employee_result) > 0){
while($row_employee = $employee_result->fetch_assoc()) {
$pid = $unitinid;
$eid= $row_employee['user_id'];
$ephone = $row_employee['mobile_number'];
$emailphone= $row_employee['mobile_number'].''. $row_employee['pemail'];
$unitcrewinsert= "insert into crew_assignment (date_time, pid, crew_member, phone_number, message_number, confirmed)
values ('$timenow', $pid, $eid , '$ephone', '$emailphone', 0)";
if(mysqli_query($conn, $unitcrewinsert)){
echo "Records inserted successfully.";
echo '<p> Crew Inserted </p>';
} else{
echo "<p>ERROR: Could not able to execute $unitinsert. " . mysqli_error($conn).'</p>';
}
}
}
}
Your best bet is to provide a start date and an end date and get the number of days between them. Then it's just a matter of looping through each day and assigning it to an array. Could probably use the same logic to solve the weeks as well.
Example:
$d1 = Carbon::parse($start_date);
$d2 = Carbon::parse($end_date);
$num_days = $d1->diffInDays($d2) + 1;
$dates = array();
for ($i = 1; $i <= $num_days; $i++) {
array_push($dates, date('Y-m-d', strtotime($start_date.' +'.$i.' days')));
}
var_dump($dates);
I am not sure this is the best way, however it works.
<?php
include 'connection.php';
date_default_timezone_set("America/New_York");
// Start date
$date = '2018-05-18';
// End date
$end_date = '2018-05-31';
while (strtotime($date) <= strtotime($end_date)) {
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
$dayn = date('N', strtotime($date));
echo "<p> $date </p>";
echo "<p> $dayn </p>";
$units = "select e.user_id, e.station, e.full_name, max(e.level) level, es.unit, es.days, es.start_time, es.total_hours from employees e
left join employee_schedule es on es.pid = e.user_id
where es.days like '%$dayn%' and e.status = 1
group by es.unit";
$units_result = $conn->query($units);
//Roll through all employees who work tomorrow and place then in appropriate unit.
if($units_result->num_rows > 0){
while ($row_unit = $units_result->fetch_assoc()) {
if ($row_unit['level'] == 3) {
$level = 1;
} elseif ($row_unit['level'] == 4) {
$level = 2;
} elseif ($row_unit['level'] == 5) {
$level = 3;
} elseif ($row_unit['level'] == 8) {
$level = 4;
}
//Get Unit ID from each group
$unitid = $row_unit['unit'];
$intime = $date . ' ' . $row_unit['start_time'];
$total_hours= $row_unit['total_hours'];
$length = "+ $total_hours ";
$intimes = strtotime("$intime");
$endtime = strtotime("$length", "$intimes");
$endtime = date('Y-m-d H:i:s', $endtime);
$station = $row_unit['station'];
$timenow = date('Y-m-d H:i:s');
echo "<p>I am scheduling unit number $unitid to be on at $intime and leave at $total_hours </p>";
$unitinsert = "insert into schedules (date_time, unit, level_of_service, start_time, total_hours, station)
values ('$timenow', $unitid, $level , '$intime', '$total_hours', $station)";
if (mysqli_query($conn, $unitinsert)) {
echo "Records inserted successfully.";
$unitinid = $conn->insert_id;
echo $unitinid;
} else {
echo "ERROR: Could not able to execute $unitinsert. " . mysqli_error($conn);
}
$inspectioninsert= ""
$employee = "select e.*, es.unit, es.days, pc.email as pemail from employees e
left join employee_schedule es on es.pid = e.user_id
left join phone_carriers pc on pc.id = e.phone_carrier
where es.days like '%$dayn%'and es.unit = $unitid and e.status = 1";
$employee_result = $conn->query($employee);
if (mysqli_num_rows($employee_result) > 0) {
while ($row_employee = $employee_result->fetch_assoc()) {
$pid = $unitinid;
$eid = $row_employee['user_id'];
$ephone = $row_employee['mobile_number'];
$emailphone = $row_employee['mobile_number'] . '' . $row_employee['pemail'];
$unitcrewinsert = "insert into crew_assignment (date_time, pid, crew_member, phone_number, message_number, confirmed)
values ('$timenow', $pid, $eid , '$ephone', '$emailphone', 0)";
if (mysqli_query($conn, $unitcrewinsert)) {
echo "Records inserted successfully.";
echo '<p> Crew Inserted </p>';
} else {
echo "<p>ERROR: Could not able to execute $unitinsert. " . mysqli_error($conn) . '</p>';
}
}
}
}
}
}
?>
Im trying to make an appointment booking system, in which everything else works, EXCEPT the appointment time slots, in which if, for example, an appointment is set at 11.30am, and lasts an hour (12.30pm), no one can book or have an appointment within these times.
I have converted start and end times of the input to unix time, as well as converting the times already set in the database, but it is failing me.
I have tried comparing the end time in between the two times set by the user, and the end time of the user between the two times already in the database.
My code is:
if ($length == "1 Hour"){
$edittime = $time;
$timeedit = strtotime($edittime)+3600;
$endtime = date('h:i:s', strftime($timeedit));
} elseif ($length == "1 Hour 30 Minutes") {
$edittime = $time;
$timeedit = strtotime($edittime)+5400;
$endtime = date('h:i:s', strftime($timeedit));
} elseif ($length == "2 Hour") {
$edittime = $time;
$timeedit = strtotime($edittime)+7200;
$endtime = date('h:i:s', strftime($timeedit));
} else {
header("location:Cancel.php");
}
/*Comparison of the start and end times, as well as the user input time.*/
$querysql = "SELECT Time FROM $tablename WHERE Time <= '$endtime' AND Date = '$date'";
$queryresult = mysqli_query($connection, $querysql);
/*Validate the query.*/
if (! $queryresult) {
echo ("Could not retrieve the sql data : " . mysqli_error($connection) . " " . mysqli_errno($connection));
}
/*Array to collect data from the sql query, to compare against the appointment times the user entered.*/
$count = 0;
$starttime = $time;
$secondtime = strtotime($starttime);
$existapp[$count] = mysqli_fetch_array($queryresult, MYSQLI_NUM);
while ($existapp[$count] <> "") {
$temp = $existapp[$count];
$acquireddata = $temp[$count];
$appsec = strtotime($acquireddata);
if ($length == "1 Hour") {
$existstart = $appsec;
$existedit = $existstart + 3600;
$existend = date('h:i:s', strftime($existedit));
} elseif ($length == "1 Hour 30 Minutes") {
$existstart = $appsec;
$existedit = $existstart + 3600;
$existend = date('h:i:s', strftime($existedit));
} elseif ($length == "2 Hour") {
$existstart = $appsec;
$existedit = $existstart + 3600;
$existend = date('h:i:s', strftime($existedit));
}
/*$timeedit = end time*/
/*$secondtime = start time*/
/*$existededit = exisiting appointment*/
if ($timeedit <= $existedit and $timeedit >= $existstart) {
header("location:Cancel.php");
}
$count = $count + 1;
}
If you need the whole file then just give me a shout.
I've been searching to no end with this, and after checking the unix times, it should work! But it doesnt! ):
<?php
/*Checks if user is logged in, else redirect to home.*/
session_start();
if(! $_SESSION['Username']) {
header("location:Index.php");
}
/*Sets variables as the login to the database, as well as tables of interest.*/
$servername = "";
$username = "";
$password = "";
$dbname = "";
$tablename = "appointmentinformation";
$tablenamed = "clientinformation";
/*Connect to the database server and the database.*/
$connection = mysqli_connect("$servername", "$username", "$password", "$dbname") or die("Could not connect to the database");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*Retrieve the username from the current session.*/
$clientusername = $_SESSION['Username'];
/*Retrieve the ClientID of interest from a table, with a parameter of the username. Limit the amount of results to one row (one result).*/
$sql = "SELECT ClientID FROM $tablenamed WHERE Username = '$clientusername' LIMIT 1";
/*Validate the query.*/
$results = mysqli_query($connection, $sql);
if (! $results) {
echo ("Could not select the data : " . mysql_error());
} else {
$datarows = mysqli_fetch_row($results);
$clientid = $datarows[0];
}
/*Retrieve user input.*/
$date = $_POST["date"];
$time = $_POST["time"];
$length = $_POST["length"];
/*Format date*/
$date = str_replace('/', '-', $date);
/*Protection from SQL injection attacks.*/
$date = stripslashes($date);
$time = stripslashes($time);
$length = stripslashes($length);
$date = mysqli_real_escape_string($connection, $date);
$time = mysqli_real_escape_string($connection, $time);
$length = mysqli_real_escape_string($connection, $length);
if ($length == "1 Hour"){
$edittime = $time;
$timeedit = strtotime($edittime)+3600;
} elseif ($length == "1 Hour 30 Minutes") {
$edittime = $time;
$timeedit = strtotime($edittime)+5400;
} elseif ($length == "2 Hour") {
$edittime = $time;
$timeedit = strtotime($edittime)+7200;
} else {
header("location:Cancel.php");
}
/*Comparison of the start and end times, as well as the user input time.*/
$querysql = "SELECT Time FROM $tablename WHERE Time <= '$endtime' AND Date = '$date'";
$queryresult = mysqli_query($connection, $querysql);
/*Validate the query.*/
if (! $queryresult) {
echo ("Could not retrieve the sql data : " . mysqli_error($connection) . " " . mysqli_errno($connection));
}
/*Array to collect data from the sql query, to compare against the appointment times the user entered.*/
$count = 0;
$starttime = $time;
$secondtime = strtotime($starttime);
$existapp[$count] = mysqli_fetch_array($queryresult, MYSQLI_NUM);
while ($existapp[$count] <> "") {
$temp = $existapp[$count];
$acquireddata = $temp[$count];
$appsec = strtotime($acquireddata);
if ($length == "1 Hour") {
$existstart = $appsec;
$existedit = $existstart + 3600;
} elseif ($length == "1 Hour 30 Minutes") {
$existstart = $appsec;
$existedit = $existstart + 3600;
} elseif ($length == "2 Hour") {
$existstart = $appsec;
$existedit = $existstart + 3600;
}
/*$timeedit = end time*/
/*$secondtime = start time*/
/*$existededit = exisiting appointment*/
if ($timeedit <= $existedit and $timeedit >= $existstart) {
header("location:Cancel.php");
}
$count = $count + 1;
}
/*SELECT query to retrieve data from the database. A complex query due to two parameters.*/
$sqlquery = "SELECT * FROM $tablename WHERE Date = '$date' AND Time = '$time'";
$sqlresult = mysqli_query($connection, $sqlquery);
/*Validate the query.*/
if (! $sqlresult) {
echo ("Could not retrieve the sql data : " . mysqli_error($connection) . " " . mysqli_errno($connection));
}
$rows = mysqli_fetch_row($sqlresult);
$date1 = $rows[3];
$time1 = $rows[4];
/*Compare the date and times and validate.*/
if ($date === $date1 && $time = $time1) {
echo("This date/time is taken!");
header("location:CreateAppointmentForm.php");
} else {
/*Insert the data into the database if validation passes.*/
$query = "INSERT INTO appointmentinformation (ClientID, Length, Date, Time) VALUES ('$clientid', '$length', '$date', '$time')";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location:UserCP.php");
} else {
echo ("Could not insert data : " . mysqli_error($connection) . " " . mysqli_errno($connection));
}
}
?>
You should change strftime to strtotime
http://php.net/manual/en/function.strftime.php
http://php.net/manual/en/function.strtotime.php
strftime first parameter is string format, second timestamp http://php.net/manual/en/function.strftime.php but you give timestamp as first parameter: for example calculated here $timeedit = strtotime($edittime)
I am getting user tweets and mentions and inserting into table. Once this process completes, I redirect to next page.
For few users it correctly stores and display tweets and redirect to next page. But for few user, it stuck on the first page where I get tweets and store into table. I am trying since last few days to overcome this.
Can any one tell me what problem can cause this? Does it is due to it unable to store the data (tweet text) into table?
There are two function in which I perform insert operation:
function lookup($tweetid,$connection,$userid)
{
$tweets5 = $connection->get("https://api.twitter.com/1.1/statuses/retweets/".$tweetid.".json?count=1");
//var_dump($tweets5);
$json = json_encode($tweets5);
foreach($tweets5 as $item)
{
$text = $item->text;
$text_id = $item->id;
// $user_id = $item->user->id;
$name = $item->user->name;
$constant = 'retweet';
$time = $item->created_at;
$dt = \DateTime::createFromFormat('D M d H:i:s e Y', $time);
// $dt = new \DateTime($time);
$tweet_time = $dt->format('H:m:s');
$tweet_dtm = $dt->format('Y:m:d');
$year = $dt->format('Y');
$month = $dt->format('m');
echo $text."-".$text_id."-".$name."-".$time."-".$tweet_time.$tweet_dtm.$year.$month.$rt_count.$follower.$friend."<br>";
echo "<br>";
$inreplyto = $item->in_reply_to_screen_name;
$follower = $item->user->followers_count;
$rt_count = $item->retweet_count;
$friend = $item->user->friends_count;
$con = mysqli_connect('127.0.0.1', 'root', 'karim', 'karim');
$text = mysql_real_escape_string($text);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$insertQuery1 = "INSERT INTO twitter_retweet(`username`,`userid`,`tweet_text`,`text_id`,`time`,`month`,`year`,`date`,`user_follower_count`,`rt_count`,`constant`,`in_reply_to`) VALUES ('".$name."','".$userid."','".$text."','".$text_id."','".$tweet_time."','".$month."','".$year."','".$tweet_dtm."','".$follower."','".$rt_count."','".$constant."','".$inreplyto."')";
if (!mysqli_query($con,$insertQuery1))
{
die('Error: ' . mysqli_error($con));
// echo "error";
}
// echo "Text : $text <br> ID : $user_id <br> Name : $name <br> Follower : $follower <br> Friends : $friend <br> ---";
}
}
Is there anything wrong in this code? I am not sure whether it stuck here during insertion or what.
2nd function, this prints the data, but it does not store $text into database. why?:
foreach ($tweets1 as $item)
{
$text = $item->text;
//echo $userid.$text;
$text_id = $item->id;
$constant = 'mention';
$time = $item->created_at;
//echo $time;
//$dt = new DateTime('#' . strtotime($time));
$dt = \DateTime::createFromFormat('D M d H:i:s e Y', $time);
//var_dump($dt);
$tweet_time = $dt->format('H:m:s');
$tweet_dtm = $dt->format('Y:m:d');
$year = $dt->format('Y');
$month = $dt->format('m');
$user_name = $item->user->name;
// echo $year.$month.$user_name;
$inreplyto = $item->in_reply_to_screen_name;
$rt_count = $item->retweet_count;
$follower_count = $item->user->followers_count;
echo $text."-".$text_id."-".$time."-".$tweet_time.$tweet_dtm.$year.$month.$user_name.$rt_count.$follower_count."<br>";
echo "<br>";
$con = mysqli_connect('127.0.0.1', 'root', 'karim', 'karim');
//$text = mysqli_real_escape_string($text);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$insertQuery1 = "INSERT INTO twitter_mention(`username`,`userid`,`tweet_text`,`text_id`,`time`,`month`,`year`,`date`,`user_follower_count`,`rt_count`,`constant`,`in_reply_to`) VALUES ('".$twitteruser."','".$userid."','".$text."','".$text_id."','".$tweet_time."','".$month."','".$year."','".$tweet_dtm."','".$follower_count."','".$rt_count."','".$constant."','".$inreplyto."')";
if (!mysqli_query($con,$insertQuery1))
{
die('Error: ' . mysqli_error($con));
// echo "error";
}
}
This is the code at the end to redirect to next page:
echo '<form name="myForm" id="myForm" action="start.php" method="POST">
<input style="display:none" name="userid" value="'.$userid.'" />
</form>
<script>
function submitform()
{
document.getElementById("myForm").submit();
}
window.onload = submitform;
</script>
';
I have two tables that my Query affects. The tables are called flightSched & Alteration. In both tables the arrivalTime column is of type TIME.
The query runs just fine until the $CurrentTimePlus4Hours variable elapses midnight. When this happens, the query doesn't yield any records, although the table has data ranging from all times of the day and night. Find below my code.
$currentDay = date('l');
$CurrentTimeMinus30min = date('H:i:s', strtotime('-30 minutes'));
$CurrentTimePlus4Hours = date('H:i:s', strtotime('+240 minutes'));
$query2 = "SELECT * FROM flightSched WHERE don = '$currentDay'
AND depOrArriv='Arrival'
AND arrivalTime BETWEEN '$CurrentTimeMinus30min' AND '$CurrentTimePlus4Hours'
ORDER BY arrivalTime ASC ;";
$query2 .= "SELECT * FROM Alteration WHERE don = '$currentDay'
AND depOrArriv='Arrival'
AND arrivalTime BETWEEN '$CurrentTimeMinus30min' AND '$CurrentTimePlus4Hours'
ORDER BY arrivalTime ASC ;";
/* execute multi query */
if ($mysqli->multi_query($query2)) {
do
{
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_array()) {
echo "<tr " . $variable . "><td>";
echo '<img src="php/displayImage.php?id=' . $row['id'] . ' "align="middle" width="110" height="35" >' . " "
. $row['flightNo'] ;
$flightNo = $row['flightNo'];
echo "</td><td>";
echo $row['airline'];
echo "</td><td>";
echo $row['origin'];
echo "</td><td>";
echo $row['arrivalTime'];
echo "</td><td>";
echo $row['status'];
echo "</td></tr>";
if ($variable == 'id=basicBoard')
{
$variable = 'class=alt';
//echo $variable;
}
elseif ($variable == 'class=alt')
{
$variable = 'id=basicBoard';
//echo $variable;
}
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
// printf("-----------------</br>");
}
}
while (#$mysqli->next_result());
echo "</table> <br/> <br/>";
}
I have tried to figure out why this happens but failed to fix the issue. Can someone kindly point out where I am going wrong in the code?
I think you just need to compensate for the time lapse by offsetting what the "current" day is:
$midnight = strtotime('today');
$now = time();
$tomorrow = $midnight + 86400;
$diff = $tomorrow - $now;
$offset = $now;
// Number of seconds in 240 minutes = 14400
if ($diff <= 14400) {
$offset += $diff;
}
$currentDay = date('l', $offset);
$CurrentTimeMinus30min = date('H:i:s', strtotime('-30 minutes'));
$CurrentTimePlus4Hours = date('H:i:s', strtotime('+240 minutes'));