feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I figured out one way , but it seems over complicated and mass code that i havent even put in my db fetches etc .
this way works, but it sucks.
Code: Select all
<?php
function makeSelectMenu1($menuName1, $options1, $chosen1) {
$list1 = '';
foreach ($options1 as $option1 => $text1) {
$selected1 = ($chosen1 == $option1) ? ' selected="selected"' : '';
$list1 .= " <option value=\"$option1\"$selected1>$text1</option>\n";
}
return "\n<select name=\"$menuName1\" id=\"$menuName1\">\n$list1</select>\n";
}
session_start();
$options1 = array(
'' => 'Choose Your Favorite Color',
'red' => 'I like Red',
'blue' => 'I like Blue',
'green' => 'I like Green'
);
$menuName1 = 'favoriteColor';
$chosen1 = '';
if (isSet($_POST[$menuName1])) $_SESSION[$menuName1] = $_POST[$menuName1];
if (isSet($_SESSION[$menuName1])) $chosen1 = $_SESSION[$menuName1];
$selectMenu1 = makeSelectMenu1($menuName1, $options1, $chosen1);
?>
<html>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $selectMenu1; ?>
<br><br>
<form2 method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $selectMenu2; ?>
<input type="submit" />
</body>
</html>
yeah that works but , imagine if i put in the calls to the database for the values etc ,that code will be like 2 gigbytes lol
is there a simple way to echo that back , like say something as in : selected="<?php echo selected ?>" ??
obviously thst doesnt work there but i mean it as an example for what would be more programmer friendly .
Thanks
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]