Re: Drop-down box in php
| From: | Andras Got | Date: | Tue, 20 Apr 2004 16:13:02 +0000 |
| Subject: | Re: Drop-down box in php | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-33975@lists.php.net to get a copy of this message | ||
You mean <select></select> html dropdown-s?
print '<select name="sg">';
$r = mysql_query("SELECT id, field1, fieldn FROM table WHERE fieldn = 'sg'");
while($RESULT = mysql_fetch_array($)) {
print '<option value="'.$RESULT['id'].'">'.$RESULT['fieldn']'.</option>';
}
print '</select>';
Validating: just check the $_POST['sg'] value, against is_numeric(), then you can do a SELECT, to check whether the id exists.
You can find some more examples, on php net manual pages
andrej
andy amol wrote:
hi, I would like to know how to create and populate drop down boxes in php. I want the value to be populated from database. What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. Also if you can help me with a date validation program I will be grateful. Thanks in advance. --------------------------------- Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢