| | |
how to display calendar through php in html table
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
hello,
I have written some code for it but it's not displaying date's in <td>
where is the problem can any body tell me.
I have written some code for it but it's not displaying date's in <td>
where is the problem can any body tell me.
php Syntax (Toggle Plain Text)
<?php //Get year 2008 $year = date('Y'); echo "Year $year</br>"; //get month $month = date('n'); echo "Month $month</br>"; //get day $day = date('j'); echo "Day $day</br>"; //get no of days in month $daysInMonth = date('t',mktime(0,0,0,$month,1,$year)); echo "Days in Month $daysInMonth</br>"; //get first day of the month $firstDay = date('w',mktime(0,0,0,$month,1,$year)); echo "First Day of Month $firstDay</br>"; //Calculate total no's of cell needed $tempDays = $firstday + $daysInMonth; echo "Temp days $tempDays</br>"; //Calculate total rows needed $weeksInMonth = ceil($tempDays/7); echo "Weeks in month $weeksInMonth</br>"; //filling the values in 2-d array //function function fillArray() { // create a 2-d array for($j=0;$j<$this->$weeksInMonth;$j++) { for($i=0;$i<7;$i++) { $counter++; $this->$week[$j][$i] = $counter; // offset the days $this->$week[$j][$i] -= $this->$firstDay; if (($this->$week[$j][$i] < 1) || ($this->$week[$j][$i] > $this->$daysInMonth)) { $this->$week[$j][$i] = ""; } } } } ?> <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <title> Calendar 2008 </title> <meta name="generator" content="editplus"> <meta name="author" content=""> <meta name="keywords" content=""> <meta name="description" content=""> </head> <body> <form name="f1" id="f1" method="post"> <center>Month : <select name="cboMonth"> <?php for($m=1;$m<=12;$m++) { echo '<option value="'. $m .'">' . $m. '</option>'; } ?> </select> Year : 2008 </center> </form> <table border="1" cellpadding="2" cellspacing="2" align="center" width="400"> <th colspan='7'><?= date('M', mktime(0,0,0,$month,1,$year)).' '.$year; ?></th> <tr> <th>Sun</th> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> </tr> <?php foreach ($week as $key => $val) { echo '<tr>'; for ($i=0;$i<7;$i++) { echo '<td align="center">'. $date .'</td>'; } echo '</tr>'; } ?> </table> </body> </html>
Last edited by cscgal; Oct 8th, 2008 at 3:05 pm. Reason: Added code tags
I have checked your code and the last piece of php code at the end of the script should look something like below. Notice how I added $date=0 and $date+=1. That is because the date you were saying that wasn't being displayed hadn't been assigned any value at all. So try using the below code.
And please use code tags next time.
php Syntax (Toggle Plain Text)
<?php $date=0; foreach ($week as $key => $val) { echo '<tr>'; // here you may need to add $date+=1; or $date-=1; for ($i=0;$i<7;$i++) { $date+=1; echo '<td align="center">'. $date .'</td>'; } echo '</tr>'; } ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- IE7 document.getElementById problem (JavaScript / DHTML / AJAX)
- how to pass a php array to a sql query (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
- Warning: mysql_num_rows(): (PHP)
- vBulletin mod_rewrite for vB 3.0.7 (Existing Scripts)
Other Threads in the PHP Forum
- Previous Thread: to display the running time as clock in page
- Next Thread: Multiple languages site?
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend






