RE: [PHP] Select box

From: Date: Tue, 18 May 2004 08:50:14 +0000
Subject: RE: [PHP] Select box
Groups: php.general 
Request: Send a blank email to php-general+get-186461@lists.php.net to get a copy of this message
On 18 May 2004 09:06, Brent Clark wrote: > Hi all > > For the likes of me I cant seem to figure out how to have a > select drop down > box , and have it so, that when I click the submit button, > the page displays > the correct content (which is what it does) but at the same > time I need the > select box to be at the option of the query. > > Below is part of my code. > > If someone could help, it would be most appreciated. > > <select name="uname"> > <?php > $sqlu="SELECT id,user,name FROM users > ORDER BY user > ASC"; > $name_result = mysql_query($sqlu); > while($rowu=mysql_fetch_array($name_result)){ > echo"<option > value=\"$rowu[user]\">$rowu[user]</option>\n"; > } > > > </select> Assuming that this form submits to itself, so $_POST['uname'] will be set to the selected value: $selected = @$_POST['uname']; while($rowu=mysql_fetch_array($name_result)){ echo "<option value=\"$rowu[user]\""; if ($selected==$rowu['user']) echo ' selected'; echo "$rowu[user]</option>\n"; } Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#186461) next »