Hi there all,
I am doing a script where I have a select menu with a few options (that are generated from mysql). the thing is that I use a two step hiearchy (dunno about the spelling) and if the user chose the base case, the next page should be "index.php" and otherwise "listall.php".
An example list.
Numbers
-one
-two
-three
-four
Countries
-sweden
-austria
-france
-japan
If the user click on either "Numbers" or "Countries" he should be redirected to "index.php" but if he click on the ones with a starting "-" he should be redirected to "listall.php".
The problem I get is that the user have to press the button twice in order to get to the right place, because the script will always use the "old" variables (the ones that were set the last time).
The form code I use is: (I know it's quite a mess, but it's a cut-out from a function...)
if(!function_exists(parse_album_select)) {
function parse_album_select($sending_file, $group) {
$output ="<form action=";
$output .= "$sending_file";
$output .= "?php_file=$sending_file";
$output .= " method=\"post\">
<b>Select album: <select name=\"group\" size=1>
<option>";
$output .= $group;
$que = "SELECT DISTINCT parent FROM galleries ORDER BY parent AS
C";
$res = send_query($que);
while ($parent = mysql_fetch_array($res)) {
$output .= "<option>$parent[0]";
$query = "SELECT name FROM galleries WHERE(parent = \"$p
arent[0]\") ORDER BY id";
$result = send_query($query);
while ($grouparr = mysql_fetch_array($result)) {
$output .= "<option>";
$the_group = $grouparr[0];
$output .= "- $the_group";
}
}
$output .= "
</select>
<input type=\"Submit\" Value=\"Go\">
</form>";
return $output;
}
}
And I use the following code to determine which file to redirect to:
if(!function_exists(format_album_choice)) {
function format_album_choice($group) {
$parental= explode(" ", $group);
if($parental[0] =="-") {
$group = $parental[1];
$call_php_file = "images.php";
}else{
$call_php_file = "albums.php";
}
$output[0] = $call_php_file;
$output[1] = $group;
echo "$output[0], $output[1].";
return $output;
}
}
Thanks in advance,
/anders