php noob needs help

Joined
Oct 23, 2005
Messages
670
I'm trying to figure out how to get this calendar to function properly. It displays the current month and year correctly but I can't get it to display any other month or year at all. I'm not too familiar with php and got the basis for the calendar from the net and just added/edited to my needs. Anyways I need an option for the user to select whichever month and year they wish and for it to display the calendar correctly. Next I'm going to store whatever the user inputs in the calendar in a mysql database but before that I need to get the calendar to function properly.

Can someone look through my code and get me going in the right direction? Thanks for any help.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Calendar</title>
<style type="text/css" media="all">

    body {
    
        background-color: #FFFFFF;
        color: #000000;
        font-family: Tahoma, Verdana, sans-serif;
        font-size: 22px;
    
    }
    
    table {
    
        width: 125px;
    
    }
    
    td {
    
        padding: 1px;
        border: 1px solid #666666;
        text-align: center;
    
    }

</style>
</head>
<body>
<?php

    // get this month and this years as an int   
    if($_POST["month"] > 0)
		$thismonth = $_POST["month"];
	else
	    $thismonth = ( int ) date( "m" );    	
	
	if($_POST["year"] > 0)
		$thisyear = $_POST["year"];
	else
	    $thisyear = date( "Y" );
    
    // find out the number of days in the month
    $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $thismonth, $thisyear );
    
    // create a calendar object
    $jd = cal_to_jd( CAL_GREGORIAN, $thismonth, 1, $thisyear );
    
    // get the start day as an int (0 = Sunday, 1 = Monday, etc)
    $startday = jddayofweek( $jd , 0 );
    
    // get the month as a name
    $monthname = jdmonthname( $jd, 1 )

?>

<form method="POST submit="calendar.php">

<select name="month">
<?php
 for($month=1; $month <= 12; $month = $month+1)
 {
 		$myMonth = mktime(0, 0, 0, $month, 1, date("y"));
		$theMonth = date(F, $myMonth);
		if($month == $thismonth)
			echo "<option selected value=$month>$theMonth</option>";
		else
			echo "<option value=$month>$theMonth</option>";
 }
 echo "</select>";
?>
 
 <select name="year">
 <?php
 	$curYear = date("Y");
 	for($year = $curYear-6; $year <= $curYear+6; $year = $year+1){
 		if($year == $thisyear)
			echo "<option selected value=$year>$year</option>";
		else
		    echo "<option value=$year>$year</option>";
	}
	echo "</select>";
 ?>
 <input type="submit" name="calDate" value="Go"></input>
 </form>

<form method="POST" action=dbschedule.php">
<table>
    <tr>
        <td colspan="7"><div align="center"><strong><?= $monthname ?></strong></div></td>
    </tr>
    <tr>
        <td><strong>Sun</strong></td>
        <td><strong>Mon</strong></td>
        <td><strong>Tue</strong></td>
        <td><strong>Wed</strong></td>
        <td><strong>Thu</strong></td>
        <td><strong>Fri</strong></td>
        <td><strong>Sat</strong></td>
    </tr>
    <tr>
<?php

    // put render empty cells

    $emptycells = 0;

    for( $counter = 0; $counter <  $startday; $counter ++ ) {
    
        echo "\t\t<td></td>\n";
        $emptycells ++;
    
    }
    
    // renders the days
    
    $rowcounter = $emptycells;
    $numinrow = 7;
   
    for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) {
    
        $rowcounter ++;
        
        echo "\t\t<td>$counter<br>	
		<textarea rows=5 name=$counter
		cols=15></textarea></td>\n";
        
        if( $rowcounter % $numinrow == 0 ) {
        
            echo "\t</tr>\n";
            
            if( $counter < $numdaysinmonth ) {
            
                echo "\t<tr>\n";
            
            }
        
            $rowcounter = 0;
        
        }
    
   }
    
    // clean up
    $numcellsleft = $numinrow - $rowcounter;
    
    if( $numcellsleft != $numinrow ) {
    
        for( $counter = 0; $counter < $numcellsleft; $counter ++ ) {
        
            echo "\t\t<td></td>\n";
            $emptycells ++;
        
        }
    
    }

?>
    </tr>
    </table>
 <input type="submit" name="submit" value="Submit"></form>
 </form>
 </body>
 </html>
 
Back
Top