Re: Forms and While loop

From: Date: Thu, 02 Nov 2000 00:59:06 +0000
Subject: Re: Forms and While loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23284@lists.php.net to get a copy of this message
On Thu, 02 Nov 2000, Wayne Michel wrote: > I am trying to produce a drop-down list. Relevant (I think) code follows: > > echo "<p><form method=\"post\" > action=\"$Relative/items.php?CA=$CatID&amp;UID=$UID\"><select > name=\"CatList\" size=\"1\">"; > while ($row = mysql_fetch_row($result)) > { > $Cat=$row[0]; > $CatID=$row[1]; > echo "<option value=\"$row[0]\"> $row[0] </option>"; > } > echo "</select><input type=\"submit\" name=\"Submit\" > value=\"Go to > Category\"></p></form>"; > > It all works well except the variable $Cat is not showing in the action > line. I have to get it to work with various layouts, but I am at an > impasse. As a new PHP coder, I try to think it through, but this time I am > stuck. > > Can anyone show me how to get the variable $Cat, inside the loop, to appear > in the action line. > > Thanks In a nutshell - that's not the way to do it. If you want to access the value selected from the list, do it in the script items.php by checking the value $CatList. The name of the select list becomes the variable name. Of course you don't need the stuff in the Action value from and including the ? So you could rewrite the above: echo '<p><form method="post" action='. $Relative .'/items.php">'; echo '<select name="CatList" size="1">'; while ($row = mysql_fetch_row($result)) { $Cat=$row[0]; $CatID=$row[1]; echo '<option value="' .$CatID .'"> '.$Cat. '</OPTION>'; } echo '</select><input type="submit" name="Submit" value="Go to Category"></p></form>'; I'm assuming that you want to display the value of $Cat on the dropdown list. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#23284) next »