Populating a list box from a MySQL Database and Creating a Query page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kurty
    New Member
    • Mar 2007
    • 1

    Populating a list box from a MySQL Database and Creating a Query page

    Hello all,
    I am currently working on a project (a web based database) which entails the use of HTML, PHP and MySQL. I am new to all of these languages and would like some assistance in solving the following problem that I have encountered:
    The project entails ADDing ,EDITing, DELETing records from a web based database. However the main objective of this project is to allow users to perform queries on the data in the database and then view the results. This is the point I have reached and would like to find out how to populate a list box using the contents from a MySQL table so that users can select multiple options from several list boxes. Any assistance (especially PHP code) in solving this problem will be greatly appreciated. Thanking you all in advance.

    Regards,
    Kurty
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to TSDN.

    If you really want us to help you out, you'll have to show the code you have made until now. So, show your code.

    And show it within php or code tags, as required by the Posting Guidelines!!

    As far as populating a select box with MySQL data is concerned, the following sample shows you one way of how to accomplish this.

    [php]
    echo '<select name="wgr" >';
    echo '<option value="">Select group</option>'
    $conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS)
    or die($msg_no_con nect);
    mysql_select_db (SQL_DB, $conn)
    or die("Error connect: ".mysql_error() );
    $result=mysql_q uery("SELECT * FROM table_name")
    or die("SELECT error: ".mysql_error() );
    while ($row=mysql_fet ch_assoc($resul t)) {
    $gr = $row['group'];
    echo "<option value='$gr'>$gr </option>";
    }[/php]

    Ronald :cool:

    Comment

    Working...