You are here: Re: php best practise « PHP Programming Language « IT news, forums, messages
Re: php best practise

Posted by rlee0001 on 03/10/06 20:42

Barry,

For a combo box (drop-down select), use something like this:

<label for='fld_location' accesskey='L'><u>L</u>ocations:</label>
<select id='fld_location' name='location[]'>
<?php
// POPULATE LOCATIONS
$locations = pg_query($db_conn, 'SELECT name FROM locations ORDER BY
name;');
if ($locations) {
while ($location = pg_fetch_object($locations)) {
echo '<option
value=\''.$location->name.'\''.(($location->name==$thisrecord->location)?'
selected=\'selected\'':'').'>'.$location->name.'</option>';
}
}
?>
</select>

The ternary operator (cond?val1:val2) is used to check each option. If
the option is the one currently selected output selected='selected',
otherwise output an empty string. If you have a static list (as opposed
to a database query), just put the ternary operator in each of the
options checking each options value against the current selection.

So the same thing in radio buttons using the ternary operator except
use checked='checked'. Hope that helped.

-Robert

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация