denhamd2 Posted April 4, 2007 Share Posted April 4, 2007 Hi guys, Is it possible to make a calendar in PHP rather than hard-coding it in HTML? For example, I'm looking to make one for June 2007 and on each line I'd like to have the day, the date and then a checkbox containing the date, so for example: <input type="checkbox" name="date" value="01062007" /> Tues. 1st<br> Is it possible to do this dynamically using PHP? Thanks in advance Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 4, 2007 Share Posted April 4, 2007 Date picker ? run cal6.php move mouse to the right side of the textbox by the way imege is not displayed Download attached scripts. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 4, 2007 Share Posted April 4, 2007 modified [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 4, 2007 Author Share Posted April 4, 2007 thanks, but is it possible to do this purely in PHP with a simple function? Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 4, 2007 Share Posted April 4, 2007 Simple function, no, but here's a function that you can modify to your specifications. It allows you to pass two optional parameters through: one for year and one for month. It then generates and displays a calendar with days and checkboxes for each day. Use it as you will! <?php function datePicker($year = '', $month = '') { $year = empty($year) ? date('Y') : $year; $month = empty($month) ? date('m') : $month; $ts = mktime(0,0,0,$month,1,$year); $dInMo = date('t', $ts); $offset = date('w', $ts); $weeks = ceil(($offset + $dInMo) / 7); $mName = date('F Y', $ts); $wDay = array('Su', 'M', 'Tu', 'W', 'Th', 'F', 'Sa'); $out = "<table id=\"myCalendar\">\n"; $out .= "<tr>\n"; $out .= "<th colspan=\"7\">$mName</th>\n"; $out .= "</tr>\n"; $out .= "<tr>\n"; $out .= "<td>" . implode("</td>\n<td>", $wDay) . "</td>\n"; $out .= "</tr>\n"; $d = 1 - $offset; // Define your starting day // Loop your weeks for ($i = 0; $i < $weeks; $i++) { $out .= "<tr>\n"; // Loop 7 days for week for ($x = 0; $x < 7; $x++) { $out .= "<td>\n"; if ($d > 0 && $d <= $dInMo) { $dTs = mktime(0,0,0,$month, $d, $year); $out .= "<div class=\"dayValue\">$d</div>\n"; $out .= "<div class=\"checkValue\"><input type=\"checkbox\" name=\"myDates[]\" value=\"$dTs\" /></div>\n"; } else { $out .= " "; } ++$d; $out .= "</td>\n"; } $out .= "</tr>\n"; } $out .= "</table>\n"; return $out; } // Usage: echo datePicker(2007, 10); ?> Hope this helps. Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 4, 2007 Author Share Posted April 4, 2007 thanks mate please can you help me with my other thread (dropdown menu for months?) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.