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
    New Coder
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Set Retrieved Record As Selected In ComboBox

    I'm trying to populate a drop-down box (combo box) with records retrieved from a table in the database.
    The retrieval works, but when I try to set what is required to be selected, it won't set it as needed... instead the list is just populated.

    PHP Code:
    <?php
                            $queryh 
    mysql_query("SELECT StaffFirstName FROM stafftbl WHERE StaffTypeID=3");
                                                        
                                                        echo 
    "<select name='txtassignedto' id='txtassignedto'>";
                                                        
                                                        while (
    $optionsh mysql_fetch_array($queryh))
                                                        {
                                                            if(
    $optionsh == "$AssignedTo")
                                                            {
                                                                echo 
    "<option value='{$optionsh['StaffFirstName']}' selected='selected'> {$optionsh['StaffFirstName']} </option>";
                                                            }
                                                            else
                                                            {
                                                            echo 
    "<option value='{$optionsh['StaffFirstName']}'> {$optionsh['StaffFirstName']} </option>";    
                                                            }

                                                        }
                                                        echo 
    "</select>";                            
                            
    ?>

    Somewhere way above the code, the variable "AssignedTo" is set. It is retrieved from a form submitted on another page.

    PHP Code:
    $AssignedTo $_GET['AssignedTo']; 
    I can affirm that it is retrieved, as it is echoed.

  2. #2
    New Coder
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Okay.. Got it solved.

    This thread can be closed.

    If it help anyone else out there, here are the changes that I made to get it working:

  3. #3
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,095
    Thanks
    109
    Thanked 602 Times in 589 Posts
    Quote Originally Posted by AMQB View Post
    PHP Code:
                                                        
                                                        
    while ($optionsh mysql_fetch_array($queryh))
                                                        {
                                                            if(
    $optionsh == "$AssignedTo"
    Seeing as you didn't actually show us how you fixed your code...

    This is the problem. You are setting $optionsh as an array of columns and data returned from mysql but then comparing it to a string - $AssignedTo. You must compare one of the arrays values - eg $optionsh['user'] == $AssignedTo.

    That'll keep the google surfers happy..
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.


 

Tags for this Thread

Posting Permissions

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