note 65243 added to control-structures.while

From: Date: Thu, 27 Apr 2006 15:08:14 +0000
Subject: note 65243 added to control-structures.while
Groups: php.notes 
Request: Send a blank email to php-notes+get-109857@lists.php.net to get a copy of this message
Talking about while, dropdown menus, and ternary operator which was mentionned before, you can combine them to have drop menu built with a value selected according to your wishses. <select name="whatever"> <?php while ($data = mysql_fetch_assoc($requeteID)) { $menu .= '<option value="'.$data['id'].'"'; $menu .= ($data['id'] == $_GET['id'] ? ' selected>' :'>'); $menu .= $data['name'].'</option>'; } ?> </select> Therefore if you are creating a form to select data from database, and want the form displayed when search is done to show what parameters have been chosen that will do the trick !! Let's say I make a search between different sports, I choose football in my form, send my query... then displays are show, the menu will have football selected because of the ternary operator that displays "selected>" on the <option> ;) Enjoy ^^ ---- Server IP: 194.246.101.61 Probable Submitter: 193.194.132.39 (proxied: 10.221.12.186) ---- X-Spam-Status: No, hits=4.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_30_40,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/control-structures.while.php Edit -- http://master.php.net/note/edit/65243 Del: integrated -- http://master.php.net/note/delete/65243/integrated Del: useless -- http://master.php.net/note/delete/65243/useless Del: bad code -- http://master.php.net/note/delete/65243/bad+code Del: spam -- http://master.php.net/note/delete/65243/spam Del: non-english -- http://master.php.net/note/delete/65243/non-english Del: in docs -- http://master.php.net/note/delete/65243/in+docs Del: other reasons-- http://master.php.net/note/delete/65243 Reject -- http://master.php.net/note/reject/65243 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109857) next »