Thread: Drop-down

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    How can I output the results of a search on my table to web page in a drop-down menu field-box??

    In other words, if 5 records are found in my tabvle, the drop-down menu should contain these 5 records only.

    Thnx.

    Ranesh.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    You can do something like:
    $result=mysql_query("select * from tablename",$con);
    //issue the sql query..


    echo "<Select name="some name">";
    while($row=mysql_fetch_array($result)){
    echo "<option value="".$row["checkboxfieldname"]."">".$row["checkboxfieldname"]."</option>";
    }
    echo "</select>";


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited August 31, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Thank you very much Shiju. It works!!

    Ranesh.


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:
    You can do something like:
    $result=mysql_query("select * from tablename",$con);
    //issue the sql query..


    echo "<Select name="some name">";
    while($row=mysql_fetch_array($result)){
    echo "<option value="".$row["checkboxfieldname"]."">".$row["checkboxfieldname"]."</option>";
    }
    echo "</select>";

    [/quote]

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Make sure that if you have any selections in the dropdown that are two words you may want to url encode them, I just ran into this problem last week. You can do this to fix the problem:
    print '<Select name="somename">';
    while($row=mysql_fetch_array($result)){
    printf('<option value="%s">%s</option>', rawurlencode($row["checkboxfieldname"]), $row["checkboxfieldname"]);
    }
    print '</select>';
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London, England
    Posts
    16
    Rep Power
    0
    Could i ask what 'url encoding' them actually does?


  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    What if you had a field in your databse called city and in it you had a bunch of cities like Los Angeles, Boston, St Louis etc. When you selected them from the db and created the drop down it would look something like this:
    <select name="city">
    <option value="Los Angeles">Los Angeles
    <option value="Boston">Boston
    <option value="St Louis">St Louis
    </select>

    When you submitted the form the variable $city would be okay if you selected Boston because there is no space in it, but if you selected Los Angeles, $city would hold the value Los on the script page, because of the space but if you wree to urlencode the values first then it would get sent as Los+Angeles and you would get the whole shebang, you would just need to decode it on the following page so by using rawurlencode your select statement would like this:
    <select name="city">
    <option value="Los+Angeles">Los Angeles
    <option value="Boston">Boston
    <option value="St+Louis">St Louis
    </select>

Similar Threads

  1. dynamic drop down list using jsp in javascript
    By quilla_b in forum JavaScript Development
    Replies: 2
    Last Post: May 27th, 2004, 12:35 PM
  2. MySQL output to table using phpBB
    By CCCMTech in forum PHP Development
    Replies: 0
    Last Post: February 2nd, 2004, 03:43 PM
  3. refresh drop down
    By yashi in forum HTML Programming
    Replies: 1
    Last Post: September 11th, 2003, 12:12 PM
  4. How do I Generate Access 200 Db from script?
    By johnnyr77 in forum Database Management
    Replies: 0
    Last Post: September 1st, 2003, 06:45 PM
  5. Replies: 4
    Last Post: February 18th, 2002, 07:08 AM

IMN logo majestic logo threadwatch logo seochat tools logo