1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Calendar +Highlight days with events

Discussion in 'PHP' started by _matrix_, Mar 19, 2008.

  1. #1
    Hi,

    I have the following calendar script which also allows events to be added to mysql database.

    The problem that im having is trying to highlight todays date and other days that contain events in the database.

    The date is stored as datetime 0000-00-00 00:00:00 in the db

    Here is the cut down version with just the calendar itself where I havnt been able to impliment the above:

    if(isset($_GET['prev'])){ 
        if($_GET['prev'] == 'prev') { 
        $monthnum = $_GET['monthnow']--; 
        }else{ 
        $monthnum = $_GET['monthnow']++; 
        } 
        $date = getdate(mktime(0,0,0,$_GET['monthnow'],1,$_GET['yearnow'])); 
        }else{ 
        $date = getdate(); 
        } 
         
        if((isset($_GET['pge'])) || (isset($_GET['all']))){ 
        $monthnum = $_GET['monthnow']; 
        $date = getdate(mktime(0,0,0,$_GET['monthnow'],1,$_GET['yearnow'])); 
        } 
         
        $monthnum = $date['mon']; 
        $monthname = $date['month']; 
        $year = $date['year']; 
        $datetoday = getdate(mktime(0,0,0,$monthnum,1,$year)); 
        $firstweekay = $datetoday['wday']; 
        $cont = true; 
        $today = 27; 
         
        if(!isset($_GET['appt'])){ 
        $appt = date("Y-m-d"); 
        }else{ 
        $appt = $_GET['appt']; 
        } 
    
        while(($today <= 32) && ($cont)) { 
        $datetoday = getdate(mktime(0,0,0,$monthnum,$today,$year)); 
    
        if($datetoday['mon'] != $monthnum) { 
        $lastday = $today - 1; 
        $cont = false; 
        } 
        $today++; 
        } 
    
        echo '<form action="../calendar.php" method="get"> 
        <table width="160" align="center" border="1" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#ffffff"> 
          <tr> 
        <td align="center" style="padding: 6px" colspan="7" bgcolour="#999999"> 
        <a href="calendar.php?all&add='.$_GET['add'].'&prev=prev&monthnow='.$monthnum.'&yearnow='.$year.'"><<<</a> 
        <select name="monthnow" onChange="form.submit()"> 
          <option '.( $monthnum=='1' ? 'selected' : '' ).' value="1">Jan</option> 
          <option '.( $monthnum=='2' ? 'selected' : '' ).' value="2">Feb</option> 
          <option '.( $monthnum=='3' ? 'selected' : '' ).' value="3">Mar</option> 
          <option '.( $monthnum=='4' ? 'selected' : '' ).' value="4">Apr</option> 
          <option '.( $monthnum=='5' ? 'selected' : '' ).' value="5">May</option> 
          <option '.( $monthnum=='6' ? 'selected' : '' ).' value="6">Jun</option> 
          <option '.( $monthnum=='7' ? 'selected' : '' ).' value="7">Jul</option> 
        <option '.( $monthnum=='8' ? 'selected' : '' ).' value="8">Aug</option> 
          <option '.( $monthnum=='9' ? 'selected' : '' ).' value="9">Sep</option> 
          <option '.( $monthnum=='10' ? 'selected' : '' ).' value="10">Oct</option> 
          <option '.( $monthnum=='11' ? 'selected' : '' ).' value="11">Nov</option> 
          <option '.( $monthnum=='12' ? 'selected' : '' ).' value="12">Dec</option> 
        <input name="all" type="hidden" value=""> 
        <input name="add" type="hidden" value="'.$_GET['add'].'"> 
        </select> 
        <select name="yearnow" onChange="form.submit()"> 
          <option '.( $year=='2007' ? 'selected' : '' ).' value="2007">2007</option> 
          <option '.( $year=='2008' ? 'selected' : '' ).' value="2008">2008</option> 
          <option '.( $year=='2009' ? 'selected' : '' ).' value="2009">2009</option> 
          <option '.( $year=='2010' ? 'selected' : '' ).' value="2010">2010</option> 
        </select> 
    
        <a href="calendar.php?all&add='.$_GET['add'].'&prev&monthnow='.$monthnum.'&yearnow='.$year.'">>>></a> 
        </td> 
          </tr> 
          <tr> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Sun</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Mon</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Tue</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Wed</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Thu</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Fri</b></td> 
        <td style="padding: 6px" align="center" bgcolor="#BFD8BC"><b>Sat</b></td> 
          </tr> 
        '; 
    
        $day = 1; 
        $wday = $firstweekay; 
        $firstweek = true; 
        while ($day <= $lastday) { 
        if($firstweek) { 
        echo '<tr>'; 
        for ($i=1; $i<=$firstweekay; $i++) { 
        echo '<td></td>'; 
        } 
        $firstweek = false; 
        } 
        if ($wday==0) { 
        echo '<tr>'; 
        } 
    
        if(intval($monthnum) < 10) { 
        $newmonthnum = '0'.$monthnum.''; 
        } 
        elseif (intval($monthnum) >= 10) { 
        $newmonthnum = $monthnum; 
        } 
        if(intval($day) < 10) { 
        $newday = '0'.$day.''; 
        } 
        elseif(intval($day) >= 10) { 
        $newday = $day; 
        } 
         
        $link_date = "$year-$newmonthnum-$newday"; 
        if($datetoday == $day){ 
        $color = "#CCFFCC"; 
        }else{ 
        $color = "#FFFFCC"; 
        } 
         
        echo '<td style="padding: 6px" align="center" bgcolor="'.$color.'"><a href="calendar.php?pge&monthnow='.$monthnum.'&yearnow='.$year.'&add='.$_GET['add'].'&appt='.$link_date.'">'.$day.'</a></td>'; 
    
        if($wday==6) { 
         
        echo '</tr>'; 
        } 
        $wday++; 
        $wday = $wday % 7; 
        $day++; 
        } 
        echo ' 
        </table> 
        </form> 
        ';
    PHP:
    Thanks!
     
    _matrix_, Mar 19, 2008 IP