List:General Discussion« Previous MessageNext Message »
From:Gerald Clark Date:July 2 2001 7:11pm
Subject:Re: SELECT form element with PHP/MySQL
View as plain text  
Print the current value as the first entry of the pulldown.
It will be in the pulldown twice, but so what?

Nelson Goforth wrote:

> I have a Contact information page that draws from or writes to a table 
> [contact] and displays that information in an HTML form.  There is a 
> field [type] that I want to have populated from a pulldown list, and 
> that pulldown list is drawn from another table [contact_type]. I'm using 
> PHP 3.x for the interface (hopefully my remote server will upgrade 
> sometime soon).
> 
> For creating a new record, no problem - but if the form is displaying 
> data from an existing record, I want the pulldown list to indicate the 
> existing value for 'type'.  I've done a brute-force 'if-then' version of 
> this for a two value radio button, but doing a list like that could get 
> ugly.  I'm hoping that someone has a more elegant solution.
> 
> Here's the code I'm using - the pulldown displays nicely.
> 
>   $list = mysql_query("SELECT id, type FROM contact_type, $link);
> 
>   printf("<TR><TD CLASS=\"FormItem\">Contact Type: </TD>");
> 
>   printf("<TD CLASS=\"FormInput\"><SELECT NAME=toolnum>");
>   while ($row = mysql_fetch_object ($list)) {
>     printf("<OPTION VALUE=%s>%s</OPTION>", $row->id, $row->type);
>   }
>   printf("</SELECT>%s</TD></TR>\n", ($formValues) ?
> $formValues["id"] : 
> "");
> 
> 
> That last line is something I'm using to display text input values, but 
> of course it doesn't work here except to give the id number of the 
> contact type.
> 
> Any notions on this topic?  I could use a hard-coded pulldown list, but 
> I want to have the flexibility to create new values, and also to have 
> the values display in a foreign language if desired.
> 
> Thank you for any help.
> Nelson


-- 
Gerald L. Clark
gerald_clark@stripped

Thread
SELECT form element with PHP/MySQLNelson Goforth2 Jul
  • Re: SELECT form element with PHP/MySQLGerald Clark2 Jul
    • RE: SELECT form element with PHP/MySQLJosh Gasber3 Jul
      • Reporting Tool : Linux?Mazur3 Jul
        • Re: Reporting Tool : Linux?Joshua J. Kugler3 Jul
      • Re: Reporting Tool : Linux?Mazur3 Jul
        • Re[2]: Reporting Tool : Linux?Werner Stuerenburg3 Jul
      • RE: SELECT form element with PHP/MySQLNelson Goforth3 Jul
      • Re: Reporting Tool : Linux?Pete Kuczynski3 Jul
Re: SELECT form element with PHP/MySQLWerner Stuerenburg2 Jul
Re: Reporting Tool : Linux?Adam Stein5 Jul