Results 1 to 3 of 3

Thread: Create combo box

  1. #1
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Create combo box

    hi...
    Does anyine can help me, iwant to create combo box on php form, but the it value from table content.

    this is my table

    table name: country
    id---country
    1---USA
    2---England
    3---China
    4---Japan
    etc..

    i'm use Postgre DB

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm sorry, but I don't quite understand your question.

    <select name="variablename">
    <option value="value">displayedname
    <option value="value2">displayedname2
    </select>

    That will give you a drop down menu.

    Then, with php, depending on "get" or "post" method in your form tag (<form method="get">), you can use:
    $_GET['variablename'] or $_POST['variablename'] to use those sent values.

    Is this close?

    Can you please link to the page you are having trouble with? It's a bit hard to understand what you want.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <select multiple="true">
    <?php
      $dbuser = "your user";
      $dbpass = "your password";
      $dbname = "the name of the database";
      $tablename = "the name of the table";
      $conn = pg_connect("host=localhost port=5432 dbname=$dbname user=$dbuser pass=$dbpass");
      $query = "SELECT * FROM $tablename;";
      $rs = pg_query($query, $conn);
      while($row = pg_fetch_array($rs)) {
    ?>
      <option value="<?php echo($row['id']); ?>"><?php echo($row['country']); ?></option>
    <?php } ?>
    </select>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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