I am using php in my project, for which I am using a JavaScript calendar. I have an event date in my database, which I want to highlight in my calendar. I have tried the following code:
PHP
$items = '';
$selq = mysql_query("SELECT * FROM ".$gettn." WHERE template_content_id = '$gettid'");
$fetselq = mysql_fetch_array($selq);
$linkId1 = $fetselq['id'];
$getevent1 = mysql_query("SELECT * FROM `template3event` WHERE tl3_id = '$linkId1'");
//$items = array();
while($fetcgetevent1 = mysql_fetch_array($getevent1)){
$items .= date('d-F', strtotime($fetcgetevent1['date'])).',';
}
$event_date = substr($items, 0, -1);
$event_dates = explode(',', $event_date);
$Event_count = substr_count($event_date , ',');
// for($z = 0; $z <= $Event_count; $z++){
// echo $event_dates[$z].'<br>';
// }
JavaScript
// fill the month table with column headings
function day_title(day_name){
document.write("<TD ALIGN=center WIDTH=35>"+day_name+"</TD>")
}
// fills the month table with numbers
function fill_table(month,month_length)
{
day=1
// begin the new month table
document.write("<DIV CLASS='calender slide1'><P>"+month+" "+year+"</P>")
document.write("<TABLE width='240'><TR>")
// column headings
day_title("S")
day_title("M")
day_title("T")
day_title("W")
day_title("T")
day_title("F")
day_title("S")
// pad cells before first day of month
document.write("</TR><TR>")
for (var i=1;i<start_day;i++){
document.write("<TD>")
}
// fill the first week of days
for (var i=start_day;i<8;i++){
document.write("<TD><a href='#'>"+day+"</a></TD>")
day++
}
document.write("<TR>")
// fill the remaining weeks
while (day <= month_length) {
for (var i=1;i<=7 && day<=month_length;i++){
var getcurrentmonth= $('#hiddenmonth').val();
var getcurrentdate=$('#hiddendate').val();
if(getcurrentmonth === month)
{
if(getcurrentdate == day )
{
document.write("<TD><a style='color:rgb(65, 255, 0)' href='#'>"+day+"</a></TD>")
}
else
{
document.write("<TD><a href='#'>"+day+"</a></TD>")
}
}
else
{
document.write("<TD><a href='#'>"+day+"<a></TD>")
}
day++
}
document.write("</TR><TR>")
// the first day of the next month
start_day=i
}
document.write("</TR></TABLE></DIV>")
}
// end hiding -->
// CAHNGE the below variable to the CURRENT YEAR
var d = new Date();
var n = d.getFullYear();
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var mm = month[d.getMonth()];
var dd=d.getDate();
today = mm+'/'+dd+'/'+n;
year=n
var leap = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
var add = 0;
if(leap == true ){
add = 1;
}
//alert(add);
$('#hiddenmonth').val(mm);
$('#hiddendate').val(dd);
// first day of the week of the new year
today= new Date("January 1, "+year)
start_day = today.getDay() + 1 // starts with 0
fill_table("January",31)
fill_table("February",28+add)
fill_table("March",31)
fill_table("April",30)
fill_table("May",31)
fill_table("June",30)
fill_table("July",31)
fill_table("August",31)
fill_table("September",30)
fill_table("October",31)
fill_table("November",30)
fill_table("December",31)
I have used a query to fetch data from the database. I don't know how to proceed to the next step. I only want to use this script to achieve this, I don't want to use jQuery.
Related
I don't know either its the correct title for this question. Please, help me to edit this question if I am not adding appropriate title.
I am trying to work with hall space booking for event. There are three types of space booking:
Full - 0 (Can book by one team at same time)
Half - 1 (Can book by 2 team at same time)
Shared - 2 (Can book by 4 teams at same time)
So, I write following mention code.
<?php
$obj0 = new stdClass();
$obj0->id = '1';
$obj0->start = '2019-06-28';
$obj0->end = '2019-06-28';
$obj0->start_time = '07:00:00';
$obj0->end_time = '08:00:00';
$obj0->hall_space = '1';
$obj1 = new stdClass();
$obj1->id = '7';
$obj1->start = '2019-06-28';
$obj1->end = '2019-06-28';
$obj1->start_time = '06:00:00';
$obj1->end_time = '07:00:00';
$obj1->hall_space = '1';
$obj2 = new stdClass();
$obj2->id = '2';
$obj2->start = '2019-06-29';
$obj2->end = '2019-06-29';
$obj2->start_time = '07:00:00';
$obj2->end_time = '08:00:00';
$obj2->hall_space = '1';
$obj3 = new stdClass();
$obj3->id = '8';
$obj3->start = '2019-06-29';
$obj3->end = '2019-06-29';
$obj3->start_time = '06:00:00';
$obj3->end_time = '07:00:00';
$obj3->hall_space = '1';
$obj4 = new stdClass();
$obj4->id = '3';
$obj4->start = '2019-06-30';
$obj4->end = '2019-06-30';
$obj4->start_time = '07:00:00';
$obj4->end_time = '08:00:00';
$obj4->hall_space = '1';
$obj5 = new stdClass();
$obj5->id = '9';
$obj5->start = '2019-06-30';
$obj5->end = '2019-06-30';
$obj5->start_time = '06:00:00';
$obj5->end_time = '07:00:00';
$obj5->hall_space = '1';
$data = array($obj0, $obj1, $obj2, $obj3, $obj4, $obj5);
$hall_space = 1; //this means user is trying to book half space
if(count($data) > 0) {
$half = 0;
$shared = 0;
$error = false;
$looping_date = '';
$same_date = 0;
switch ($hall_space) {
case '0':
echo "aa";
$error = true;
break;
case '1':
foreach ($data as $dk => $dv) {
if($looping_date == $dv->start){
$same_date = $same_date + 1;
}else{
$same_date = 0;
}
if ($dv->hall_space == 0) {
echo "bb";
$error = true;
} elseif ($dv->hall_space == 1) {
$half = $half + 1;
if ($half == 2) {
echo "cc";
$error = true;
}
} elseif ($dv->hall_space == 3) {
$shared = $shared + 1;
if ($shared == 2) {
echo "dd";
$error = true;
}
}
}
break;
case '2':
foreach ($data as $dk => $dv) {
if ($dv->hall_space == 0) {
echo "ee";
$error = true;
} elseif ($dv->hall_space == 1) {
$half = $half + 1;
if ($half == 2) {
echo "ff";
$error = true;
}
} elseif ($dv->hall_space == 2) {
$shared = $shared + 1;
if ($shared == 3) {
echo "gg";
$error = true;
}
}
}
break;
}
}
if( isset($error) ){
echo "error";
}else{
echo "not error";
}
This was working fine for a singe event (i.e non-repeating). But, this is not working correctly for repeating events.
Here, in this scenario user trying to book half-space(i.e value 1) for date 2019-06-28 to 2019-06-30 from 6 am to 8am.
Above mentioned $data represents all the already booked events for that time frame, that means on every day there are are two half-spaced events (one from 6-7am and next from 7-8am) on each day. Which means this new events (half-spaced) should be allowed to book.
But, my logic is not working because, it is considering all those events as they are going to held in same date and time.That means, $half variable should be increased only if the events are on same date and time and finally should not generate error.
I tried to explain everything from myside, also you can just copy and paste the code for test. And, let me know if you need any further details.
$bookings = [
[
'period' => new DatePeriod(
new DateTime('2019-06-28 07:00:00'),
new DateInterval('PT1H'),
new DateTime('2019-06-28 08:00:00')
),
'byWho' => ['1' => 0.5, '2' => 0.5]
],
[
'period' => new DatePeriod(
new DateTime('2019-06-28 08:00:00'),
new DateInterval('PT1H'),
new DateTime('2019-06-28 09:00:00')
),
'byWho' => ['2' => 0.5]
]
];
Example data structure, between 7 and 8 on 2019-06-28 team '1' booked half the hall. Between 7 and 9 team '2' booked half the hall. All bookings should be 1 hour, if they're longer than an hour such as team two then they actually have two bookings right next to each other. If 1 hour is too long then you can change the interval if you like.
So instead of having an array of who booked when which is what you have, instead here you have an array showing a timeline, you just need to look at a specific time to see if it's booked and how full it is.
This way is better than yours because you can easily keep those dates sorted, bring this data in and out of a database into this structure with ease. Now because it's sorted you can really easily find the time you're booking for and you only need to look at the space available for that time period. But for yours you need to check every single booking to see if there is space.
If you want to check if there is space for a specific time you can use a binary search (choose your own search if you want to make this easier) to find an intersecting DatePeriod, then check values either side to find any other matching date periods. Then you simply do a check to see if in those periods there's space to fit the booking. To check for space it's as easy as summing up the values in 'byWho' + your booking size and see if it's greater than 1.
I have this function that creates textareas deepening on the month. So if it is march, then 31 textareas. But the problem is right now that I cannot add anything into my db. I tried to make my function into arrays, and he change my php so it is like the function. But im not sure on where the issue lies. The problem is that it inserts empty values in the MySQL db.
function:
var showDate = new Date();
var months = ["Januari", "Februari", "March", "April", "May", "June",
"July", "Augusti", "September", "October", "November", "December"];
var weeks = ["Sunday","Monday","Tuseday","Wednesday","Thursday","Friday","Saturday"];
function drawTable(forDate) {
const daysInMonth = new Date(
forDate.getFullYear(),
forDate.getMonth() + 1,
0
).getDate();
const date = [
forDate.getFullYear(),
(forDate.getMonth() + 1 + '').padStart(2, 0)
]
.join('-');
const table = document.getElementById("table");
table.innerHTML = "";
for (let day = 1; day <= daysInMonth; day++) {
const dateString = date + '-' + (day + '').padStart(2, 0);
const row = document.createElement("tr");
const cell = document.createElement("td");
const textarea = document.createElement("textarea");
textarea.setAttribute("name", "day[]");
textarea.setAttribute("value", dateString);
textarea.innerHTML = dateString;
textarea.setAttribute("placeholder", day);
cell.appendChild(textarea);
row.appendChild(cell);
table.appendChild(row);
}
return table;
}
window.onload = function() {
document.getElementById("displayingMonth").innerHTML = months[showDate.getMonth()];
drawTable(showDate );
};
function daysInMonth(month, year) {
var days;
switch (month) {
case 1: // Feb, our problem child
var leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
days = leapYear ? 29 : 28;
break;
case 3:
case 5:
case 8:
case 10:
days = 30;
break;
default:
days = 31;
}
return days;
}
php:
<?php
$days = $_request['day'];
echo $error = "day is empty";
if(is_array($days)){
foreach ($days as $day) {
$day = mysqli_real_escape_string($conn, $day);
if (empty($day)) {
echo $error;
}
else {
!mysqli_query(
$conn, "INSERT INTO table (day) VALUES('$day')");
}
}
}
if (count($error)) {
print_r($error);
}
?>
html:
<h1 id="displayingMonth"></h1>
<form action="index.php" method="post">
<table id="table"></table>
<input id="btn" type="submit" value="Press" />
</form>
I get my error msg: "day is empty"
Having a look at this line
textarea.setAttribute("name", "day[]");
you are in fact passing the day array to PHP
Change your PHP to this:
<?php
if (isset($_POST['submit'])) {
$error = '';
$days = $_POST['day'];
if (is_array($days)){
foreach ($days as $day) {
$day = mysqli_real_escape_string($conn, $day);
echo $day . '<br />';
if (empty($day)) {
echo $error;
} else {
mysqli_query($conn, "INSERT INTO table (day) VALUES ('$day')");
}
}
}
if (count($error)) {
print_r($error);
}
}
?>
The code checks if the submit button has been pressed (add name="submit" to your submit button) and then retrieves the day array submitted in the POST. You should consider changing $_REQUEST to $_POST, as this is a POST request. Note the uppercase $_REQUEST as opposed to $_request. The latter gave an error for me, so perhaps you don't have errors enabled. Try adding
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
to the top of your PHP script and setting
`display_errors = on`
inside your php.ini file.
Hope this helps!
how to fetch value from post method and explode in foreach loop.
public function generate_all_payslip() {
$data['title'] = "Generate All Payslip";
$this->payroll_model->_table_name = "tbl_department"; //table name
$this->payroll_model->_order_by = "department_id";
$all_dept_info = $this->payroll_model->get();
// get all department info and designation info
$dataalldep = array();
foreach ($all_dept_info as $v_dept_info) {
$dataalldep['all_department_info'][] = $this->payroll_model->get_add_department_by_id($v_dept_info->department_id);
}
foreach ($dataalldep['all_department_info'] as $keyemp=>$valemparray) {
$datae = array();
foreach($valemparray as $k=>$v) {
$datae['flag'] = 1;
$datae['designations_id'] = $v->designations_id;
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
$datae['payment_date'] = $currentyear."-".$currentmonth;
$datae['employee_info'] = $this->payroll_model->get_emp_salary_list($emp = NULL, $datae['designations_id']);
$basicwagessalaey = $datae['employee_info'][0]->basic_salary;
$gross = $datae['employee_info'][0]->house_rent_allowance + $datae['employee_info'][0]->medical_allowance + $datae['employee_info'][0]->special_allowance + $datae['employee_info'][0]->fuel_allowance + $datae['employee_info'][0]->phone_bill_allowance + $datae['employee_info'][0]->other_allowance;
$deduction = $datae['employee_info'][0]->tax_deduction + $datae['employee_info'][0]->provident_fund + $datae['employee_info'][0]->other_deduction;
$net_extra = $gross - $deduction;
$workingdayscurrentmonth = $this->countDays($currentyear,$currentmonth, array(0));
$perdaysaaryperuser = $basicwagessalaey/30;
### full day ###
$queryfullday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='1' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray = $queryfullday->result_array();
$attendancecounting = $attendancecountarray[0]['present_days'];
//$attendancecounting = 24;
$data['attendancecounting'] = $attendancecountarray[0]['present_days'];
if ($attendancecounting == $workingdayscurrentmonth) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*30)+$perdaysaaryperuser;
} else {
if ($workingdayscurrentmonth == 27) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*3);
}
if ($workingdayscurrentmonth == 26) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*4);
}
if ($workingdayscurrentmonth == 25) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*5);
}
if ($workingdayscurrentmonth == 24) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*6);
}
}
### half day ###
$queryhalfday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='2' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_half = $queryhalfday->result_array();
$attendancecounting_half = $attendancecountarray_half[0]['present_days'];
//$attendancecounting_half = 1;
$data['attendancecounting_half'] = $attendancecountarray_half[0]['present_days'];
$data['totalmonthwages_half'] = ($perdaysaaryperuser/2)*$attendancecounting_half;
### leave day ###
$queryleave = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='3' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_leave = $queryleave->result_array();
$attendancecounting_leave = $attendancecountarray_leave[0]['present_days'];
//$attendancecounting_leave = 2;
$data['attendancecounting_leave'] = $attendancecountarray_leave[0]['present_days'];
$data['totalmonthwages_leave'] = $perdaysaaryperuser*$attendancecounting_leave;
### absent day ###
$queryabsent = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='0' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_absent = $queryabsent->result_array();
$attendancecounting_absent = $attendancecountarray_absent[0]['present_days'];
//$attendancecounting_absent = 1;
$data['attendancecounting_absent'] = $attendancecountarray_absent[0]['present_days'];
$data['totalmonthwages_absent'] = $perdaysaaryperuser*$attendancecounting_absent;
######################
$querylastsalary = $this->db->query("SELECT * FROM `tbl_salary_payment` WHERE employee_id='".$data['employee_info'][0]->employee_id."' Order BY salary_payment_id desc LIMIT 1");
$lastsalary = $querylastsalary->result_array();
$paymentamountlastmonth = $lastsalary[0]['payment_amount'];
$data['totalmonthwage'] = ($data['totalmonthwagesfullday']+$data['totalmonthwages_half']+$net_extra)-($data['totalmonthwages_absent']);
if ($paymentamountlastmonth < 0) {
$data['totalmonthwages'] = $data['totalmonthwage']+$paymentamountlastmonth;
} else {
$data['totalmonthwages'] = $data['totalmonthwage'];
}
########## insert into tbl_salary_payment ##########
if ($datae['employee_info'][0]->employee_id !="") {
$dbinsert = array();
$dbinsert['employee_id'] = $datae['employee_info'][0]->employee_id;
$dbinsert['basic_salary'] = $datae['employee_info'][0]->basic_salary;
$dbinsert['house_rent_allowance'] = $datae['employee_info'][0]->house_rent_allowance;
$dbinsert['medical_allowance'] = $datae['employee_info'][0]->medical_allowance;
$dbinsert['special_allowance'] = $datae['employee_info'][0]->special_allowance;
$dbinsert['fuel_allowance'] = $datae['employee_info'][0]->fuel_allowance;
$dbinsert['phone_bill_allowance'] = $datae['employee_info'][0]->phone_bill_allowance;
$dbinsert['other_allowance'] = $datae['employee_info'][0]->other_allowance;
$dbinsert['tax_deduction'] = $datae['employee_info'][0]->tax_deduction;
$dbinsert['provident_fund'] = $datae['employee_info'][0]->provident_fund;
$dbinsert['other_deduction'] = $datae['employee_info'][0]->other_deduction;
$dbinsert['payment_for_month'] = $datae['payment_date'];
$dbinsert['payment_type'] = 'Cash Payment';
$dbinsert['payment_date'] = date('Y-m-d H:i:s');
$dbinsert['payment_amount'] = round($totalmonthwages);
$dbinsert['present'] = $attendancecounting;
$dbinsert['halfday'] = $attendancecounting_half;
$dbinsert['leave'] = $attendancecounting_leave;
$dbinsert['absent'] = $attendancecounting_absent;
$insertedid = $this->payroll_model->insertpayrolldata($dbinsert);
####### insert into tbl_salary_payslip ###
$dbinsertpayslip = array();
$dbinsertpayslip['payslip_number'] = date('Ymd');
$dbinsertpayslip['salary_payment_id'] = $insertedid;
$this->payroll_model->insertpayslipdata($dbinsertpayslip);
}
}
}
$data['subview'] = $this->load->view('admin/payroll/generate_all_payslip', $data, TRUE);
$this->load->view('admin/_layout_main', $data);
}
error with this code only
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
if I use
$currentyear = date('Y');
$currentmonth = date('m');
its work fine.but i want use date that i have selected not current system date
how do i correct this code. currently i see this error
This page isn’t workingexample.com is currently unable to handle this request.HTTP ERROR 500
Is there any specific resason to use below mentioned line?
$datepaymentmades = explode("-",$dataee['payment_date']);
Or you let us know what you want to do with this.
If you want month, date and year than please check below.
$paymentDate = strtotime($dataee['payment_date']);
$month = date("m",strtotime($paymentDate));
$year = date("Y",strtotime($paymentDate));
$day = date("d",strtotime($paymentDate));
I have 2 date ranges in my Codeigniter App, and i want to calculate the number of days that intersects between those to ranges. any ideas?
Date1start = YYYY-MM-DD;
Date1end = YYYY-MM-DD;
Date2start = YYYY-MM-DD;
Date2end = YYYY-MM-DD;
Something like this should work
$datetimeStart1 = new DateTime('2015-12-10');
$datetimeEnd1 = new DateTime('2015-12-20');
$datetimeStart2 = new DateTime('2015-12-12');
$datetimeEnd2 = new DateTime('2015-12-28');
// following http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
if ($datetimeStart1 < $datetimeEnd2 && $datetimeEnd1 > $datetimeStart2) {
echo min($datetimeEnd1,$datetimeEnd2)->diff(max($datetimeStart2,$datetimeStart1))->days+1;
} else {
echo 'no overlap';
}
Demo: http://3v4l.org/9Pecb
Only for PHP 5.2
$datetimeStart1 = new DateTime('2015-12-10');
$datetimeStart1 = $datetimeStart1->format('U');
$datetimeEnd1 = new DateTime('2015-12-20');
$datetimeEnd1 = $datetimeEnd1->format('U');
$datetimeStart2 = new DateTime('2015-12-12');
$datetimeStart2 = $datetimeStart2->format('U');
$datetimeEnd2 = new DateTime('2015-12-28');
$datetimeEnd2 = $datetimeEnd2->format('U');
// following http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
if ($datetimeStart1 < $datetimeEnd2 && $datetimeEnd1 > $datetimeStart2) {
echo round(
((min($datetimeEnd1,$datetimeEnd2)) - (max($datetimeStart2,$datetimeStart1))) / (60*60*24)) + 1;
} else {
echo 'no overlap';
}
Demo: http://3v4l.org/a1WLk
Write it easy:
$datetimeStart1 = new DateTime('2015-12-10');
$datetimeEnd1 = new DateTime('2015-12-20');
$datetimeStart2 = new DateTime('2015-12-12');
$datetimeEnd2 = new DateTime('2015-12-28');
$start = max($datetimeStart2,$datetimeStart1);
$end = min($datetimeEnd1,$datetimeEnd2);
echo $end >= $start ? $end->diff($start)->days+1 : "no overlap";
I have the script below and on the website http://cacrochester.com, sometimes the contents of the right sidebar load and sometimes they don't. I think it's if it's your first few times on a page, it will say no events scheduled.
I'm completely stumped on why this is happening. The data in the database is not changing.
Let me know if you need me to post anymore code.
Thanks for helping!
<?php
$dummy = 0;
$headingLength = 0;
$descriptionLength = 0;
$shortHeading = 0;
$shortDescription = 0;
$todayYear = date('Y');
$todayMonth = date('m');
$todayDay = date('d');
$events = new dates();
$noEvents = 0;
//get the number of upcoming events
$numEvents = $events->getNumberEvents();
//get the actual events
$results = $events->getRows();
//used if there are not at least 5 events to fill up the event scroller
switch($numEvents) {
case 1: $dummy = 4; break;
case 2: $dummy = 3; break;
case 3: $dummy = 2; break;
case 4: $dummy = 1; break;
}
//loops through all of the events in the table and adds them to the list
foreach($results as $result)
{
$strippedHeading = stripslashes($result['heading']);
$strippedDescription = stripslashes($result['description']);
$headingLength = strlen($strippedHeading);
$descriptionLength = strlen($strippedDescription);
$shortHeading = $strippedHeading;
$shortDescription = $strippedDescription;
$time = strftime("%l:%M %P", $result['time']);
$location = $result['location'];
$startDate = getdate($result['start_date']);
$today = getdate();
//if the events are NOT in the past...
if($startDate >= $today)
{
//if we are at the end of the array, add the class 'last' to the li
if(current($result) == end($result))
{
echo "<li class=\"last\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></li>".PHP_EOL;
}
else
{
echo "<li><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></li>".PHP_EOL;
}
$noEvents = 1;
}
//if there is not at least 5 events, it repeats the events in the list until there are 5 total
elseif($dummy > 0 && $numEvents > 0)
{
//if the events are NOT in the past...
if($startDate >= $today)
{
//if we are at the end of the array, add the class 'last' to the li
if($dummy == 0)
{
echo "<li class=\"last\"><h4>".$shortHeading."</h4> ".$shortDescription."</li>".PHP_EOL;
$dummy--;
}
else
{
echo "<li><h4>".$shortHeading."</h4> ".$shortDescription."</li>".PHP_EOL;
$dummy--;
}
//if we have 5 events, do not add anymore
if($dummy < 0)
{
break;
}
}
$noEvents = 1;
}
}
//if there are no events, display the no events message
if($noEvents == 0)
{
echo "<li class=\"last\"><h4>No Events Scheduled</h4></li>".PHP_EOL;
}
?>
When you do $startDate >= $today you are trying to compare two arrays, which isn't too good an idea. Just use plain timestamps and it should work fine:
$startDate = $result['start_date'];
$today = strtotime('today');
Also, I'm not sure if this is a typo: current($result) == end($result), but shouldn't it be $results, which is the array name?