Jump to content

PHP Calendar


Mr Chris

Recommended Posts

Hi Guys,

 

I’ve been looking at an event calendar that I found one  suits my needs.

 

I made changes to the code to suit my needs, and now however, I want to make a couple more changes and would appreciate some help, as i'm stuck!.

 

The current calendar I have finds the date in the database for each event where the start_date happens and makes it a hyperlink in the calendar created.

 

Now what I want it to do is this:

 

Make the calendar find the start_date and end_date in my database for each event and makes the dates hyperlinks where they are EQUAL TO start_date OR BETWEEN OR EQUAL TO end_date.

 

Now I **think** I have my SQL statement right, but would anybody be able to help me understand how I can make the dates hyperlinks for what i'm after?

 

Thanks

 

Chris

 

<?php 
         
// Old Query Was to Just get the date
//$sql = "SELECT start_date FROM cms_events GROUP BY start_date ORDER BY start_date";

// New Query Want to get the between dates?
$sql = "SELECT * FROM cms_events WHERE start_date >= CURRENT_DATE() AND end_date <= CURRENT_DATE()";
$qry = mysql_query($sql) or die("SQL Error: $sql<br" . mysql_error()); 

$arrEVENTS = array(); 
WHILE ($r = mysql_fetch_array($qry)) : 
  $arrEVENTS[$r['start_date']] = 1; 
ENDWHILE; 

$pMON = (isset($_GET['m']) ? $_GET['m'] : gmdate("Ym")); 

$thisMONyy = substr($pMON,0,4); 
$thisMONmm = substr($pMON,4,2); 

$BOM     = gmmktime(0,0,0,$thisMONmm,1,$thisMONyy); 
$EOM     = gmmktime(0,0,0,$thisMONmm+1,0,$thisMONyy); 
$BOC     = gmmktime(0,0,0,$thisMONmm,1-gmdate("w", $BOM),$thisMONyy); 
$EOC     = gmmktime(0,0,0,$thisMONmm+1,0+(6-gmdate("w",$EOM)),$thisMONyy); 

$PREVmon = gmdate("Ym",gmmktime(0,0,0,$thisMONmm-1,1,$thisMONyy)); 
$NEXTmon = gmdate("Ym",gmmktime(0,0,0,$thisMONmm+1,1,$thisMONyy)); 

$PREVyear = gmdate("Ym",gmmktime(0,0,0,$thisMONmm,1,$thisMONyy-1)); 
$NEXTyear = gmdate("Ym",gmmktime(0,0,0,$thisMONmm,1,$thisMONyy+1)); 

print "<table style='smCal' cellspacing=0 cellpadding=0 bgcolor=c0c0c0>"; 
print "<tr bgcolor=navy>"; 
print "<td class='month' width='100%' colspan='7'>"; 
print "<table width='100%'><tr>"; 
print "<td align='left'>"; 
print "<a href='{$_SERVER['PHP_SELF']}?m=$PREVyear'>«</a> "; 
print "<a href='{$_SERVER['PHP_SELF']}?m=$PREVmon'><</a>"; 
print "</td>"; 
print "<td class='month'>" . gmdate("F Y", $BOM) . "</td>"; 
print "<td align='right'>"; 
print "<a href='{$_SERVER['PHP_SELF']}?m=$NEXTmon'>></a>"; 
print "<a href='{$_SERVER['PHP_SELF']}?m=$NEXTyear'>»</a>"; 
print "</td>"; 
print "</tr></table>"; 
print "</td>"; 
print "<tr>"; 

print "<tr class='header'>"; 
$DOWheader = array("Su","Mo","Tu","We","Th","Fr","Sa"); 
foreach($DOWheader as $dow => $thisHEADER) : 
  print "<td align='right'><b>$thisHEADER</b></td>"; 
endforeach; 
print "</tr>\n"; 

$rows = 0; 
$x = $BOC; 
DO { 
  $dow = gmdate("w", $x); 
  if ($dow == 0) : print "<tr>\n"; endif; 
  $thisSTYLE = ""; 
  IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) : 
    $thisSTYLE = "style='color:DarkGreen;'"; 
  ENDIF; 
  print "<td class='" . (gmdate("Ym",$x) == $pMON ? "active" : "inactive") . "'>"; 
  IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) : 
  print "<a href=\"javascript:void(null);\" onclick=\"pop_up('details.php?start_date=" . gmdate("Y-m-d", $x) . "');\">"; 
  ENDIF; 
  print gmdate("j",$x); 
  IF (isset($arrEVENTS[gmdate("Y-m-d",$x)])) : 
    print "</a>"; 
  ENDIF; 
  print "</td>\n"; 
  if ($dow == 6) : print "</tr>\n"; $rows++; endif; 
  $x+=86400; 
} WHILE ($x <= $EOC and $rows <= 5); 

print "<table>"; 
?>

 

Link to comment
https://forums.phpfreaks.com/topic/49854-php-calendar/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.