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

    Join Date
    Jul 2006
    Posts
    251
    Rep Power
    17

    Drop down options issue


    I feel like I am close with this one. Very simply I have a drop down where the items are drawn from a table. We could have an item selected by checking another table. However, if the user has selected an item and hit submit that will either override the existing value or if an existing value doesnt exist: create a new record.

    So my problem from the code below is that while when selecting or drawing the existing value the outcome is expected, when the user hits submit, the page returns with the selected option not displaying in the drop down.

    PHP Code:

    //get the records for the drop down
        $uprecord_status = 'active';
        $up_rec_select = $DB_con2->prepare('select up_table_names_id, recordname, record_label from setup_user_preference_table_names where status = :status');
        $up_rec_select->execute(array(":status"=>$uprecord_status));
        $up_rec_select_result = $up_rec_select->fetchAll(); 
    ?>


      <select name="up_recordname_select">
        <option>Select</option>
        <?php 
        
    //if the user has submited the form then display the selected value
               
    if (isset($_POST['display']) && isset($_POST['up_recordname_select'])){
               
    $uprecordname_selected $_POST['up_recordname_select'];
              echo 
    "<option value='$uprecordname_selected' selected:selected>$record_label</option>";           
           }    
            
    //for each value form the database display them, if one is equal to the record stored in the database then show that as selected               
          
    foreach ($up_rec_select_result as $up_row) { 
          
    $uprecordname_original $up_row['recordname'];
          
    $up_table_names_id_original $up_row['up_table_names_id'];
          
    $record_label $up_row['record_label'];

          if (
    $uprecordname_selected ==  $uprecordname_original){
              echo 
    "<option value='$uprecordname_selected' selected:selected>$record_label</option>";
          }
         
    //show the values in the drop down
            
    echo  "<option value='$uprecordname_original'>$record_label</option>";
          }
        


    ?>
        </select>
        </div>
    How can I organize this better to meet my requirement?

    Thanks,

    G
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,914
    Rep Power
    9646
    "selected:selected" is quite incorrect. Close, but took a detour down the wrong road. Try again.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    251
    Rep Power
    17
    Originally Posted by requinix
    "selected:selected" is quite incorrect. Close, but took a detour down the wrong road. Try again.
    Thanks got it sorted.

    G

IMN logo majestic logo threadwatch logo seochat tools logo