how to display calendar through php in html table

Reply

Join Date: Apr 2007
Posts: 28
Reputation: jatinder_44 is an unknown quantity at this point 
Solved Threads: 0
jatinder_44's Avatar
jatinder_44 jatinder_44 is offline Offline
Light Poster

how to display calendar through php in html table

 
0
  #1
Oct 8th, 2008
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.
  1. <?php
  2. //Get year 2008
  3. $year = date('Y');
  4. echo "Year $year</br>";
  5.  
  6. //get month
  7. $month = date('n');
  8. echo "Month $month</br>";
  9.  
  10. //get day
  11. $day = date('j');
  12. echo "Day $day</br>";
  13.  
  14. //get no of days in month
  15. $daysInMonth = date('t',mktime(0,0,0,$month,1,$year));
  16. echo "Days in Month $daysInMonth</br>";
  17.  
  18. //get first day of the month
  19. $firstDay = date('w',mktime(0,0,0,$month,1,$year));
  20. echo "First Day of Month $firstDay</br>";
  21. //Calculate total no's of cell needed
  22. $tempDays = $firstday + $daysInMonth;
  23. echo "Temp days $tempDays</br>";
  24. //Calculate total rows needed
  25. $weeksInMonth = ceil($tempDays/7);
  26. echo "Weeks in month $weeksInMonth</br>";
  27. //filling the values in 2-d array
  28. //function
  29. function fillArray()
  30. {
  31. // create a 2-d array
  32. for($j=0;$j<$this->$weeksInMonth;$j++)
  33. {
  34. for($i=0;$i<7;$i++)
  35. {
  36. $counter++;
  37. $this->$week[$j][$i] = $counter;
  38. // offset the days
  39. $this->$week[$j][$i] -= $this->$firstDay;
  40. if (($this->$week[$j][$i] < 1) || ($this->$week[$j][$i] > $this->$daysInMonth))
  41. {
  42. $this->$week[$j][$i] = "";
  43. }
  44. }
  45. }
  46. }
  47. ?>
  48. <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  49. <html>
  50. <head>
  51. <title> Calendar 2008 </title>
  52. <meta name="generator" content="editplus">
  53. <meta name="author" content="">
  54. <meta name="keywords" content="">
  55. <meta name="description" content="">
  56. </head>
  57. <body>
  58. <form name="f1" id="f1" method="post">
  59. <center>Month : <select name="cboMonth">
  60. <?php
  61. for($m=1;$m<=12;$m++)
  62. {
  63. echo '<option value="'. $m .'">' . $m. '</option>';
  64. }
  65. ?>
  66. </select>
  67. Year : 2008
  68. </center>
  69. </form>
  70. <table border="1" cellpadding="2" cellspacing="2" align="center" width="400">
  71. <th colspan='7'><?= date('M', mktime(0,0,0,$month,1,$year)).' '.$year; ?></th>
  72. <tr>
  73. <th>Sun</th>
  74. <th>Mon</th>
  75. <th>Tue</th>
  76. <th>Wed</th>
  77. <th>Thu</th>
  78. <th>Fri</th>
  79. <th>Sat</th>
  80. </tr>
  81. <?php
  82. foreach ($week as $key => $val)
  83. {
  84. echo '<tr>';
  85. for ($i=0;$i<7;$i++)
  86. {
  87. echo '<td align="center">'. $date .'</td>';
  88. }
  89. echo '</tr>';
  90. }
  91. ?>
  92. </table>
  93. </body>
  94. </html>
Last edited by cscgal; Oct 8th, 2008 at 3:05 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,472
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: how to display calendar through php in html table

 
0
  #2
Oct 8th, 2008
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.
  1. <?php
  2. $date=0;
  3. foreach ($week as $key => $val)
  4. {
  5. echo '<tr>';
  6. // here you may need to add $date+=1; or $date-=1;
  7. for ($i=0;$i<7;$i++)
  8. {
  9. $date+=1;
  10. echo '<td align="center">'. $date .'</td>';
  11. }
  12. echo '</tr>';
  13. }
  14. ?>
And please use code tags next time.
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC