Jump to content

select problam with range.


redarrow

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]
Link to comment
https://forums.phpfreaks.com/topic/23978-select-problam-with-range/
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]
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]

Archived

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

×
×
  • Create New...

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.