Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002

    Unanswered: Using PHP and mySQL to populate listbox

    My experience with PHP until this point was with "PHP only" scripts (no HTML included in code). I've now built my page in Dreamweaver so my form looks pretty, but I guess pretty doesn't mean much if I don't know how to make it work. So, I think I need someone's help.

    I have 2 questions regarding PHP's interaction with forms.

    On my page I have 3 radio buttons (first,after,last)
    Next to the "after" radio button I have a drop-down listbox (after_list)

    Maybe my first question doesn't involve PHP but how do I go about making the "after" radio button select the "after_list" listbox?

    My second question regards embeding PHP into HTML. How would I write the PHP code into my Dreamweaver HTML to querry the mySQL server and populate the listbox with a columns' information?

    Any help would be greatly appreciated.

    Last edited by josh013; 03-08-02 at 03:15.

  2. #2
    Join Date
    Nov 2001
    this is how i have done it:

    <td colspan="2" class="BLACK">
    <select name="devicetypeid">
    $sql2 = "SELECT *
    while ( $dropdown = mysql_fetch_array($result2) ){
    if ($dropdown["DEVICETYPEID"]==$devicetypeid){
    echo("<option selected value=". $dropdown["DEVICETYPEID"]. ">" . $dropdown["DESCRIPTION"] . "</option>");
    else {
    echo("<option value=". $dropdown["DEVICETYPEID"]. ">" . $dropdown["DESCRIPTION"] . "</option>");

  3. #3
    Join Date
    Feb 2002
    New Jersey
    If you're using it more than one location then build a function and just call the function in your page.

    function def:
    function optionBlockRecipe()
    $dbConn = new MyConnect();
    $sql = "SELECT recipe_id, menu_name FROM menu_item ORDER BY menu_name";
    $rs = mysql_query($sql, $dbConn->conn)or die("Connection to DataBase failed");

    for($i = 0; $i < mysql_num_rows( $rs ); $i++)
    $tmp = mysql_fetch_row( $rs );
    print("<OPTION value=\"$tmp[0]:$tmp[1]\">$tmp[1]</OPTION>\n");

    call anywhere by inserting in php tags( except if you're already within the php tags...)

    <?php optionBlockRecipe(); ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts