Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

select problam with range.

Recommended Posts

can you see why the $day select is outputting the range as a whole and not as the select box as intrnded palease help cheers.

[code]
<?php

if($_POST['submit']){

foreach($dates as $x){

echo $x;

}

}

echo "<form method='POST' action='' ";


$day=range(1,31);

echo"<select name='dates[]'>";

foreach($day as $d){

echo"<option value='$d'>$d</option>";
}
echo"</select>";



$month=range(1,12);

echo"<select name='dates[]'>";

foreach($month as $n){

echo"<option value='$n'>$n</option>";
}
echo"</select>";


$year=range(2006,2020);

echo"<select name='dates[]'>";

foreach($year as $y){

echo"<option value='$y'>$y</option>";
}
echo"</select><br><br>";


echo "<input type='submit' name='submit' value='send'>";

echo "</form>";


?>

[/code]

Share this post


Link to post
Share on other sites
echo "<form method='POST' action='' ";

should you end that? action=''>

Share this post


Link to post
Share on other sites
I came up with this as a date select box.

what do you think is it acceptable.

[code]
<?php

if($_POST['submit']){

$x=implode("-",$dates);

$result=mktime($x);// timestamp for the database

echo date("d-m-y",$result); // format timestamp any order

}


echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'> ";


$day=range(1,31);

echo"<select name='dates[]'>";

foreach($day as $d){

echo"<option value='$d'>$d</option>";
}
echo"</select>";



$month=range(1,12);

echo"<select name='dates[]'>";

foreach($month as $n){

echo"<option value='$n'>$n</option>";
}
echo"</select>";


$year=range(2006,2020);

echo"<select name='dates[]'>";

foreach($year as $y){

echo"<option value='$y'>$y</option>";
}
echo"</select><br><br>";


echo "<input type='submit' name='submit' value='send'>";

echo "</form>";


?>
[/code]

Share this post


Link to post
Share on other sites
There we go a full working select box for dates.

[code]
<?php

if($_POST['submit']){

$result1=date("d-m-Y", mktime(0, 0, 0, $dates[1], $dates[0], $dates[2]));


echo " This is the date you selected $result1";

$result2=strtotime($result1);

echo "<br>This is the timestamp for the date you selected $result2";

}


echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'> ";


$day=range(1,31);

echo"<select name='dates[]'>";

foreach($day as $d){

echo"<option value='$d'>$d</option>";
}
echo"</select>";


$month=range(1,12);

echo"<select name='dates[]'>";

foreach($month as $n){


echo"<option value='$n'>$n</option>";
}
echo"</select>";


$year=range(2006,2020);

echo"<select name='dates[]'>";

foreach($year as $y){


echo"<option value='$y'>$y</option>";
}
echo"</select><br><br>";


echo "<input type='submit' name='submit' value='send'>";

echo "</form>";


?>

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.