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
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.