0

I have seen one answer to this, but I didn't understand something - what goes where the question marks are (on the 6th line)?. Looked around for a while, but someone probably has the answer on the tip of their tongue. - (Yes, I know I'm mixing escape characters in my code, but I'm in the beginning of trying to create cleaner/better code, and I probably shouldn't mix PHP and HTML)

  <select name="teacher"> ';
        $empquery = "SELECT * FROM `employees` ORDER BY `lastname`";
        $empresults = $pdo->query($empquery);
        while ($emprow = $empresults->fetch()) {
            echo "<option value=".$emprow['id'];
            if (?????????? == $emprow['id']) 
                echo "selected = 'selected'";   
            echo "> {$emprow['lastname']} {$emprow['firstname']}</option> ";    
        } 
  echo ' </select>
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Chris Wilson
  • 203
  • 1
  • 6
  • 14
  • there should be another variable that determins which option is selected. if your id is equal to something than that option is selected, don't know how to explain it better – v0d1ch Jan 03 '13 at 20:08
  • The original post I looked at was here: [link](http://stackoverflow.com/questions/199597/populate-select-drop-down-from-a-database-table) - But I didn't get where the variable "$selected_venue_id" in the top-ranking answer actually came from. – Chris Wilson Jan 03 '13 at 20:23

2 Answers2

0

as vodich suggested there should be another variable which holds the current value or selected value

for example

if you want to assign a contact person for a department, you might want to compare the contact person of that department (if it already has one) with the select list options values

wonde
  • 1,181
  • 10
  • 20
0

Oh... I just got it - Apologies for lameness of question. For those who come after me:

In my case, the variable in the ???? should be the one that held a value when the user is sent to this web page in the FIRST place. I had a page where a classroom was selected, then this page loads the classroom info. The classroom info along with a teacher ID was sent to this form.

This form allows the user to select a different teacher for the classroom. The default (selected="selected") value is in that variable (array) I sent to this page.

Thanks for explaining guys.

Chris Wilson
  • 203
  • 1
  • 6
  • 14