note 65243 deleted from control-structures.while by sobak

From: Date: Fri, 02 Dec 2016 08:23:23 +0000
Subject: note 65243 deleted from control-structures.while by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207944@lists.php.net to get a copy of this message
Note Submitter: startide at free dot fr ---- 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>'; } echo $menu; ?> </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 ^^

« previous php.notes (#207944) next »