Results 1 to 5 of 5
  1. #1

    a little php / mysql help

    could anybody help with a little problem I have.

    I have some value's stored in a mysql table, they are stored as


    ~value1~~value2~~value3~~value4 etc

    I can use php to connect to the mysql table and print the data as
    ~value1~~value2~~value3~~value4 etc

    but is there any way I can make the data appear as a dropdown list of values for a html form.

    for example like

    <select name=options>
    <option>value1</option>
    <option>value2</option>
    <option>value3</option>
    <option>value4</option>
    </select>

    thankyou in advance for any responces

  2. #2
    Join Date
    Mar 2004
    Posts
    1,301
    hi,

    you might want to try the following:

    $sql = mysql_query("SELECT yourvalue FROM yourtable") or die(mysql_error());

    echo'<select name = option>';
    while($i=mysql_fetch_array($sql)) {
    echo '<option value="'.$i['yourvalue'].'">'.$i['yourvalue'].'</option>';
    }
    echo'</select>';

    That's what i've been using for my program. Hope it work for you too


    BTW, if you don't want to include the value, you may omit that, and just use:

    echo'<option>'.$i['yourvalue'].'</option>';
    Last edited by orbitz; 03-22-2004 at 10:41 AM.

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Try this
    PHP Code:
    $values "value1~~value2~~value3~~value4";
    $parts  explode("~~",$values);
    echo 
    "<select>";
    while(list(,
    $val) = each($parts))
    {
       echo 
    "<option>".$val."</option>";
       }
       echo 
    "</select>"
    Last edited by Burhan; 03-22-2004 at 11:40 AM.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    thanks very much. :-)

  5. #5
    Join Date
    Mar 2004
    Posts
    1,301
    $values = "value1~~value2~~value3~~value4";


    ohhhh, that's what you meant! sorry i misunderstood your question craigj

Posting Permissions

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