Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Location
    Tampa
    Posts
    223
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Selecting Initial Value on a dynamic dropdown box

    I have a drop down box and am trying to figure out how to select the initial value from the results of a query on my page. Any help would be greatly appreciated.

    Here is my dropdown:

    PHP Code:
    <select name="dcstatus" id="dcstatus">
                            <option value="">Please Choose One</option>
                            <?php do { ?><option value="<?php echo $row_folder_status['dcstatusid']; ?>"><?php echo $row_folder_status['dcstatusname']; ?></option><?php } while ($row_folder_status mysql_fetch_array($folder_status)); ?>
                          </select>
    Here is my query:

    PHP Code:
    $folder mysql_query("SELECT dcname, dcdescription, dcparent, dccreator, dcstatus FROM dcmain WHERE dcid = '$dcid'") or die(mysql_error());
    $row_folder mysql_fetch_array($folder);
    $row_folder_total mysql_num_rows($folder); 

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    use a counter, and if the counter is equal to 1, then print selected="selected"

    else do nothing

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Which option did you want to set to be selected? If it's the first option in the list, then Whizard's suggestion would work fine... otherwise you just need to compare the current query row's value to whatever value it is you want selected (that part's not clear).

    BTW you are using two different variables in that query: $row_folder_status and $row_folder... that will cause problems unless it is just a copy/paste error.


  •  

    Posting Permissions

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