
Gazzahbay
New Members-
Posts
6 -
Joined
-
Last visited
Everything posted by Gazzahbay
-
Include Checkbox in Simple PHP Calendar Script
Gazzahbay replied to Gazzahbay's topic in PHP Coding Help
I've got it to the point of mostly working... A bit of CSS to hide unwanted checkboxes <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; $thisTime = mktime(0,0,0,$cMonth,1-$startday,$cYear); $endTime = mktime(0,0,0,$cMonth,$maxday,$cYear); for ($i=0; $i<($maxday+$startday); $i++, $thisTime <= $endTime) { if(($i % 7) == 0 ) echo "<tr>"; if($i < $startday) echo "<td align='center' valign='middle' height='20px'> </td>"; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "<br />"; $thisDate = date('Y-m-d', $thisTime); echo "<input name='Days[]' type='checkbox' value='".$thisDate."'"; if ($selectSelectDate == $thisDate){?> checked="checked" <?php } ?> /> <?php $thisTime = strtotime('+1 day', $thisTime); // increment for loop echo "</td>"; if(($i % 7) == 6 ) echo "</tr>"; } ?> -
Include Checkbox in Simple PHP Calendar Script
Gazzahbay replied to Gazzahbay's topic in PHP Coding Help
I'm getting closer... Changed the FOR statement to include the extra expression... Got rid of the WHILE statement... <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; $thisTime = mktime(0,0,0,$cMonth,1,$cYear); $endTime = mktime(0,0,0,$cMonth,$maxday,$cYear); for ($i=0; $i<($maxday+$startday); $i++, $thisTime <= $endTime) { if(($i % 7) == 0 ) echo "<tr>"; if($i < $startday) echo "<td></td>"; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "<br />"; $thisDate = date('Y-m-d', $thisTime); echo "<input name='Days[]' type='checkbox' value='".$thisDate."'"; if ($selectSelectDate == $thisDate){?> checked="checked" <?php } ?> /> <?php $thisTime = strtotime('+1 day', $thisTime); // increment for loop echo "</td>"; if(($i % 7) == 6 ) echo "</tr>"; } ?> Now what happens is that the date in value is starting from the first TD in the table, not the first TD with a date. So if 4 empty TD's before the start of the month, then date is out by four days... -
Include Checkbox in Simple PHP Calendar Script
Gazzahbay replied to Gazzahbay's topic in PHP Coding Help
Date format is irrelevant until I go to stage 2, which is to include more code for entering info into DB... If you go to http://new.herveybayqld.com.au - you will see what I mean by "zillions of checkboxes" it is supposed to look like this - http://new.herveybayqld.com.au/test.php - But the value, say the checkbox on the 5th Feb 16, is just "5" instead 2016-02-05 So, am trying to change the "5" to a full date EG "2016-02-05" Cheers -
Include Checkbox in Simple PHP Calendar Script
Gazzahbay replied to Gazzahbay's topic in PHP Coding Help
Like if I change else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "<br />"; /************** START TESTING ***************/ $thisTime = mktime(0,0,0,$cMonth,1,$cYear); $endTime = mktime(0,0,0,$cMonth,$maxday,$cYear); while($thisTime <= $endTime) { $thisDate = date('d-m-Y', $thisTime); echo "<input name='selectdate' type='checkbox' value='".$thisDate."'/>"; $thisTime = strtotime('+1 day', $thisTime); // increment for loop } /************** END TESTING ***************/ echo "</td>"; TO else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "<br /><input name='selectdate' type='checkbox' value='". ($i - $startday + 1) . "'/></td>"; Works fine - except value of checkbox is just the day number EG Just "5" BUT want the value to be EG 5-1-2016 (for starters) - eventually going to MySQL Date Format (0000-00-00) once I get this stage working.. -
Include Checkbox in Simple PHP Calendar Script
Gazzahbay replied to Gazzahbay's topic in PHP Coding Help
Thanks Guys Yep, haven't got to the point of making it a form as yet (thats stage 2!!!) This stage is to merely try and get the checkboxes displaying correctly with the correct full date value IE d-m-Y. This bit here is what I'm trying to get working... (Works now, but zillions of checkboxes appear!) echo "<input name='selectdate' type='checkbox' value='".$thisDate."'/>"; If you use the code as it stands, each calendar day has a full months worth of checkboxes in the one day! iE if Jan, 31 x 31 check boxes appear.... (WHILE inside a FOR) Like paste in say http://phpfiddle.org Cheers -
Hi Team Using a simple PHP Calendar, but wish to add a checkbox with the value being the full date that will end up being added to MySQL DB. Full Code is below (as you can see I have a WHILE inside a FOR as just a test to date) So am getting a Multiple Loop... <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); $cDay = $_REQUEST["day"]; $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <!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=UTF-8" /> <title>Availability Calendar</title> </head> <body> <table width="100%"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a></td> </tr> </table></td> </tr> <tr> <td align="center"><table width="100%" border="1" cellpadding="5" cellspacing="0"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "<tr>"; if($i < $startday) echo "<td></td>"; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "<br />"; /************** START TESTING ***************/ $thisTime = mktime(0,0,0,$cMonth,1,$cYear); $endTime = mktime(0,0,0,$cMonth,$maxday,$cYear); while($thisTime <= $endTime) { $thisDate = date('d-m-Y', $thisTime); echo "<input name='selectdate' type='checkbox' value='".$thisDate."'/>"; $thisTime = strtotime('+1 day', $thisTime); // increment for loop } /************** END TESTING ***************/ echo "</td>"; if(($i % 7) == 6 ) echo "</tr>"; } ?> </body> </html> Any assistance would be much appreciated.... Cheers