Hi. I’m very new to php, have been working on an event calendar and am on the last leg of the operational side of it. Right now I’m stuck on something that seems like it should be simple enough but is not turning out that way.
I have classes for events days, regular days, and the current day that all have different colored boxes.
Regular days bring up a form when clicked, Event days are the next step where the form has been filled out and the user can see the content with the option to modify or delete, and the Current day does either, but just has a different color box. Problem I can’t get it’s event or regular day functions to work the intended way. This is what I have:
if($todaysDate == $dateToCompare){
echo "class = 'today'";
////this is what needs to be fixed, I want it to say if $events['ID'] is empty then echo this, else echo that
if(!isset($_GET['v'])){
echo "><a href='".$urlbeg."&v=true'>" . $i . " </a></td>";
}else{
echo "><a href='".$urlbeg."&f=true'>" . $i . " </a></td>";
}
//////
}else{
$sqlCount = "SELECT * FROM eventscalendar WHERE eventDate='".$dateToCompare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
if ($noOfEvent >= 1){
echo "class = 'event'";
echo "><a href='".$urlbeg."&f=true'>" . $i . " </a></td>";
}else{
echo "class = 'regday'";
echo "><a href='".$urlbeg."&v=true'>" . $i . " </a></td>";
}
}
v allows for the form to be viewed and f allows for the entered content to be viewed. I think the best way to do this would probably be to write an if statement that said if that ID doesn’t exist to perform the v action, and if it does to perform the f one. But I haven’t been able to figure out how I do that.
Right now the only glitch with the current date is that it won’t go to it’s stored information automatically when viewed after an event date, it has to be clicked twice. Furthermore it just keeps switching between the two at clicks, and I want it to stay.
Small thing, but it’s driving me nuts. Thanks for any guidance anyone might have to offer.
Thanks a lot, I got the problem fixed. Now though, I’m having kind of a strange problem with the events class. For some reason if I have an event listed for the day before ‘today’ the event day disappears from view, shifting the calendar around to compensate.
Here’s my whole section of code now:
<?php
echo "<tr>";
for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime("$year-$month-$i");
if($i==1){
$firstDay = date("w", $timeStamp);
for ($j = 0; $j < $firstDay; $j++, $counter++){
//blank space
echo "<td> </td>";
}
}
if($counter % 7 == 0){
echo "</tr><tr>";
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <= 1){
$monthstring = "0".$monthstring;
}
if($daylength <= 1){
$daystring = "0".$daystring;
}
$todaysDate = date("m/d/Y");
$dateToCompare = $monthstring . '/' . $daystring . '/' . $year;
echo "<td ";
$sqlEvent = "SELECT * FROM eventscalendar where eventDate='".$monthstring."/".$daystring."/".$year."'";
$resultEvents = mysql_query($sqlEvent);
$events = mysql_fetch_array($resultEvents);
$sqlCount = "select * from eventscalendar where eventDate='".$dateToCompare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
$tooltip = "<div>".$events['eventDate']." <br/><br/><br/><b>".$events['holiday']."<br/>".$events['heading']."<br/>".$events['event1']."<br/>".$events['event2']."<br/>".$events['event3']."<br/>".$events['event4']."</b></div>";
if($todaysDate == $dateToCompare){
echo "class = 'today'";
if(!isset($_GET['v'])){
if($noOfEvent <= 0){
echo "><span>".$i."</span></td>";
}else{
echo "><span onmouseover='tooltip.show(".htmlspecialchars($tooltip, ENT_QUOTES).");' onmouseout='tooltip.hide();'>\
". $i ."<h6>".$events['holiday']."<br/>".$events['heading']."</h6></span></td>\
";
}
}else{
if ($noOfEvent >= 1){
echo "class = 'event'";
echo "><span onmouseover='tooltip.show(".htmlspecialchars($tooltip, ENT_QUOTES).");' onmouseout='tooltip.hide();'>". $i ."<h6>".$events['holiday']."<br/>".$events['heading']."</h6></span></td>";
}else{
echo "class = 'regday'";
echo "><span>".$i."</span></td>";
}
}
}
?>
I am assuming my understanding here is right.
You need to move your SQL out of your if statement first.
$sqlCount=..
if ($sqlCount>0) {
// show link to edit/show event
}
else {
if ($today==$datetocompate) {
if ($_GET[v]) echo "... v=true"
else echo "... f=true";
}
}
I’m still having this problem. It seems like the eventday just gets bypassed if it precedes today class date. If the the eventday is triggered following the today class cell it bypasses the today class cell.
I’ve tried several different methods but none of them seem to work very well.