Grokbase Groups MySQL mysql June 2004
FAQ
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?

Search Discussions

  • Frank Bax at Jun 26, 2004 at 3:07 pm

    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 );
    }

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmysql @
categoriesmysql
postedJun 25, '04 at 11:52p
activeJun 26, '04 at 3:07p
posts2
users2
websitemysql.com
irc#mysql

2 users in discussion

Frank Bax: 1 post Kyle Texan: 1 post

People

Translate

site design / logo © 2021 Grokbase