header() not redirecting for some reason...
Moderator: General Moderators
would this be the same effect?The Ninja Space Goat wrote:Here it is again with comments to help you understand...Code: Select all
<?php /** * Range just takes a low number and a high number and returns an array * so range(1, 4) would return an array like [1,2,3,4] */ $days = range(1, 31); // Create an array with 1-31 as elements /** * This is called the ternary operator... it's the same as doing this: * if(isset($_POST['day'])) * { * $selected_day = (integer) $_POST['day']; * } * else * { * $selected_day = null; * } * * (integer) $_POST['day'] --> this is called "type casting" * all it does is basically say to php that I want whatever is in $_POST['day'], but convert it to an integer if it isn't already */ $selected_day = isset($_POST['day']) ? (integer) $_POST['day'] : null; // This should be obvious echo "<select name="days">\n"; echo " <option value=""> - Select One - </option>"; // Loop through the array that has 31 values in it to get the 31 days foreach($days as $day) { // Another ternary operation... basically "if the user selected this day, set it to selected" $selected = ($selected_day == $day) ? 'selected="selected"' : ''; echo " <option value="" . $day . "" " . $selected . ">" . $day . "</option>\n"; } echo "</select>\n"; ?>
Code: Select all
<?php
//loop event_month
$array_month = array("January" => "01", "February" => "02", "March" => "03", "April" => "04", "May" => "05", "June" => "06", "July" => "07" , "August" => "08", "Steptember" => "09", "October" => "10", "November" => "11", "December" => "12");
echo"<SELECT NAME="event_year">\n";
foreach($array_month as $key => $val){
if($val == $event_month){
echo "<OPTION VALUE="". $val ."" SELECTED>". $key ."\n";
}else{
echo "<OPTION VALUE="". $val ."">". $key ."\n";
}
}
echo "</SELECT>\n";
//loop event_day
$days = range(1, 31);
echo"<SELECT NAME="event_day">\n";
foreach($days as $day){
if($day == $event_day){
echo "<OPTION VALUE="". $day ."" SELECTED>". $day ."\n";
}else{
echo "<OPTION VALUE="". $day ."">". $day ."\n";
}
}
echo "</SELECT>\n";
//loop event_year
$years = range(2000, 2008);
echo"<SELECT NAME="event_year">\n";
foreach($years as $year){
if($year == $event_year){
echo "<OPTION VALUE="". $year ."" SELECTED>". $year ."\n";
}else{
echo "<OPTION VALUE="". $year ."">". $year ."\n";
}
}
echo "</SELECT>\n";
?>
Last edited by boo_lolly on Mon Dec 04, 2006 3:43 pm, edited 2 times in total.