You need to wrap your code in a select statement!
An option statement wont work without the select tag around it:
<html>
<body>
<select> <!-- Start the select statement -->
<!-- Your Code -->
<?php
$num = 4;
for ($i=1; $i < 10; $i++)
{
?>
<option value="<?php echo $i; ?>" <?php if($num === $i){ echo "selected"; }; ?>><?php echo $i; ?></option>
<?php
}
?>
<!-- End your code -->
</select> <!-- End the select statement -->
</body>
</html>
After your edit, it looks like this is your main problem:
$date = 2015-02-30;
This is not what you think it is. It should be quoted like this:
$date = '2015-02-30';
Otherwise, $date
is a not a string, it's a math expression that evaluates to (int) 1983
, so substr($date, 8, 2);
will evaluate to false
, not 30
, and then obviously your option won't be selected.