List:General Discussion« Previous MessageNext Message »
From:Frank Bax Date:June 26 2004 1:54pm
Subject:Re: Using SQL query to populate a html form select field
View as plain text  
At 07:52 PM 6/25/04, Kyle Texan wrote:
>I want to take 1 field in a mysql table and use that
>information to populate an html form select field
>instead of writing the html code, that way when data
>changes in that mysql field the form will always be in
>sync with the table?


You need to use a programming language like PHP.  You would code a SELECT 
to retrieve your data and dump it into an array.  Then use a PHP statement 
like:

echo FormSelect( 'field', $array, '22' );

Where:
         - 'field' is the name of field within form
         - $array contains values from database
         - 22 is default value, if any

   function FormSelect( $name, $adata, $val ) {
     $str = '<select name="' . $name . '" size="1" >';
     foreach($adata as $k=>$o) {
       $str .= '<option value="' . $k . '"';
       if( "$k"=="$val" ) $str .= ' selected ';
       $str .= '>' . $o . '</option>' . "\n";
     }
     $str .= "</select>";
     return( $str );
   }

Thread
Using SQL query to populate a html form select fieldKyle Texan26 Jun
  • Re: Using SQL query to populate a html form select fieldFrank Bax26 Jun