I need to display days of selected month and date on press of Go button.
I have tried REQUEST
and GET
to get it from URL, onchange()
but I am definitely doing something wrong. I know that the current code is static and displays values of only 9th month of 2003.
<table>
<tr>
<form id="frmA" class="form-inline" role="form" >
<td align="right">
<select id="month" name="month" class="form-control" required="required">
<option value="">Select Month...</option>
<option value='1'>January</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</td>
<td>
<select id="year" name="year" class="form-control" required="required">
<?php
foreach (range(date('Y'), $earliest_year) as $x) {
print '<option value="'.$x.'"'.($x === $already_selected_value ? '
selected="selected"' : '').'>'.$x.'</option>';}
?>
</select>
</td>
<td>
<input type="submit" value="Go!" />
</td>
</form>
</tr>
<table>
<tbody>
<?php
$date = '2003-09-01';
$end = '2003-09-' . date('t', strtotime($date));
i=1;
while(strtotime($date) <= strtotime($end) && $i <= strtotime($end)) {
$day_num = date("d/m/Y", strtotime($date));
$day_name = date('l', strtotime($date));
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "<tr><td>$day_num - $day_name</td></tr>";
i++;
}
?>
</tbody>
</table>
you lack a few things in your code : 1/ a method + an action in 'form' 2/ assign $vars before using them on line -> $date = '2003-09-01';
<table>
<tbody>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$month = $_POST['month'];
$year = $_POST['year'];
$date = "$year-$month-01";
$end = "$year-$month-" . date('t', strtotime($date));
echo"[ $month / $year / $date / $end ]";
/* code below will throw an error
$i=1;
while( (strtotime($date) <= strtotime($end)) && ($i <= strtotime($end)) ) {
$day_num = date("d/m/Y", strtotime($date));
$day_name = date('l', strtotime($date));
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "<tr><td>$day_num - $day_name</td></tr>";
i++;
}
*/
?>
</tbody>
</table>
<table>
<tr>
<form id="frmA" class="form-inline" role="form" method="post" action="mypage.php" >
<td align="right">
<select id="month" name="month" class="form-control" required="required">
<option value="">Select Month...</option>
<option value='1'>January</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</td>
<td>
<select id="year" name="year" class="form-control" required="required">
<?php
foreach (range(date('Y'), $earliest_year) as $x) {
print '<option value="'.$x.'"'.($x === $already_selected_value ? '
selected="selected"' : '').'>'.$x.'</option>';}
?>
</select>
</td>
<td>
<input type="submit" value="Go!" />
</td>
</form>
</tr></tbody>
</table>
<table>
<tbody>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$month = $_REQUEST['month'];
$year = $_REQUEST['year'];
$date = "$year-$month-01";
$end = "$year-$month-" . date('t', strtotime($date));
$i=1;
while( (strtotime($date) <= strtotime($end)) && ($i <= strtotime($end)) ) {
$day_num = date("d/m/Y", strtotime($date));
$day_name = date('l', strtotime($date));
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "<tr><td>$day_num - $day_name</td></tr>";
$i++;
}
?>
</tbody>
</table>
<form id="frmA" class="form-inline" role="form" method="post" action="mypage.php" >
<table>
<tr>
<td align="right">
<select id="month" name="month" class="form-control" required="required">
<option value="">Select Month...</option>
<option value='1'>January</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</td>
<td>
<select id="year" name="year" class="form-control" required="required">
<?php
foreach (range(date('Y'), $earliest_year) as $x) {
print '<option value="'.$x.'"'.($x === $already_selected_value ?'selected="selected"' : '').'>'.$x.'</option>';}
?>
</select>
</td>
<td>
<input type="submit" value="Go!" />
</td>
</tr>
</table>
</form>