noob with noob question


#1

I’ve read several tutorials, but I can’t seem to be able to get my drop down menus to work, I have 10 options and I want when they hit submit the same page shows info exclusive to that option, how do I do that?


#2

Please be more specific with your subject. “noob with noob question” isnt very descriptive and gets rather annoying after a while. :)

Can you post some code so we can take a look at what you are trying to do?


#3

When you get the data from the form, compare it to an array of the possible choices and echo out the ones that don’t match.


#4

sorry about the title :D , anyway, after I compare it to an array, do I do something like if($array[] = 1) {echo “blah”}; like that? Im very new to arrays
here’s the code if it will help

<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF'];?> method="POST">
<select name="select">
<?php
$select = $_POST['select'';
$select = array(
        '1' = '1',
        '2' = '2',
        '3' = '3',
        '4' = '4',
        '5' = '5',
        '6' = '6',
        '7' = '7',
        '8' = '8',
        '9' = '9',
        '10' = '10');

$x.='<select name="select" id="select" onChange="location = this.options[this.selectedIndex].value;">';
	$x.='<option value="#">-Select a Method-</option>'."n";
foreach($select as $key => $method)
{
	$x.='<option value="?select='.$key.'"'.($key == $select ? 'selected' : '').'>'.$method.'</option>'."n";
}

	$x.='</select>';
	echo $x;
?>

[/code]


#5

Info on Arrays - http://www.php.net/types.array or there are a number of websites that explain them - google ‘php arrays’

Psuedocode Ex:

create the possible choices array - look at array()
find out how many options there are - look at count() 
    by not hard coding it you can add options with out worrying about it
start the display (table, form, whatever)
loop through the array - look at 'for' or maybe 'foreach' loops
    if the value of the array element does not equal the $_POST variable 
        echo/print the array element
    end if
end loop
stop the display

#6

Wouldn`t it have been easier just to do:

1 2 3 4 5 6 7 8 9 10 </select?

Or am I missing something?

As your values are the same in the array, you don`t need to have key value pairs in this instance. You could just have done:

$select = array( '1', '2', '3', '4', '5', '6', '7'', '8'', '9'', '10');

Your foreach loop would just have been foreach ($select as $key) and then just echo key for both value and method.

As for accessing things after, well once someone selects something from your drop down, its going to redirect with a $_GET variable. For example:

?select=1

You then need to do something based on the value selected. For example:

if ($_GET[‘select’]==1)
{
//do something
}

or you can use a switch statement:

switch ($_GET['select']) { case "1": do something; break;
 case "2":
 do something;
 break;

}

and so on. Its also worth noting that your drop down is also called ‘select’, so make sure you dont get your $_POST[‘select’] and $_GET[‘select’] mixed up.

Hope this helps.


#7

thanks, that got it!