Re: Conditional default value of drop-down list
| From: | Jason Wong | Date: | Mon, 07 Apr 2003 08:00:17 +0000 |
| Subject: | Re: Conditional default value of drop-down list | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26884@lists.php.net to get a copy of this message | ||
On Monday 07 April 2003 15:48, Jason End wrote:
> Not exactly. My application is a software catalog,
> where an admin can insert new software through a form,
> and later on, edit it through a similar form. What I
> need is that the dropdown menus in the editing form,
> reflect values set for the piece of software.
> So my categories table can look something like this:
> id descr
> 1 Operating Systems
> 2 Graphics Design
> 3 Word Processors
>
>
> And I populate the dropdown list with:
> <tr><td>Category:</td>
> <td><select name="category">
> <?
> $query = "SELECT descr from categorias";
> $result = mysql_query($query, $link);
> if(mysql_num_rows($result)) {
>
> while($row = mysql_fetch_row($result))
> {
> print("<option
> value=\"$row[0]\">$row[0]</option>");
> }
> } else {
> print("<option value=\"\">No categories
> available</option>");
> }
> ?>
> </select><br></td>
> </tr>
>
>
> What I need is that the value that the dropdown menu
> shows, is the actual category set for that software.
> The admin can then change it, but the initial value
> needs to be the correct one.
if ($row[0] == 'some_category') {
print("<option value=\"$row[0]\" SELECTED>$row[0]</option>"); }
else {
print("<option value=\"$row[0]\">$row[0]</option>");
}
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
------------------------------------------
/*
Truth is the most valuable thing we have -- so let us economize it.
-- Mark Twain
*/