Page 5 of 5

Posted: Fri Dec 01, 2006 11:23 am
by boo_lolly
AWESOME!!!!!!!!! THANK YOU SO MUCH MAN!!!! that makes it SO MUCH EASIER to deal with!!!! i LOVE this forum!!!! nothini but experts!!!

Posted: Mon Dec 04, 2006 3:28 pm
by boo_lolly
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";

?>
would this be the same effect?

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";
?>

Posted: Mon Dec 04, 2006 3:37 pm
by Luke
more or less... mine uses less code and produces valid (x)html, but the concept is the same.


Once again you haven't quoted all of your attributes!! :evil:

Posted: Mon Dec 04, 2006 3:39 pm
by boo_lolly
thanks for the quick reply! i was just wondering if the logic was the same... thanks for the tip! you da man!




....dreeee min of... that face uhgain... it's briiiiiight.... and blue.... and SHIMherin...