Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Setting 'selected' attribute of a dropdown list item based on id returned from table

$
0
0

So I'm trying to set the "selected" attribute of a dropdown list's option based on the stored id of a table. Here's my code so far which I can't seem to figure out what I'm doing wrong. Again, please note...I'm not a PHP guy...I'm an ASP.NET guy who has been literally thrown into the fire on this project. This is my first PHP project and it reminds me a lot of classic ASP from the 90's....I wish I could remember how I used to do all of this back then....

 

The standards result is the main table that contains the id of the organization within a field called organization_id. The organizations result is created by pulling the table organizations and binding that to a drop down list. I'm trying to compare the bound values with the value of organization_id in the standards table. 

while($rowStandards = mysqli_fetch_array($standards))
{
     echo "<select name='organization'>";
     while ($rowOrganizations = mysqli_fetch_array($organizations))
     {
          $selected=$rowStandards["organization_id"];
          echo "<option " . if($selected == $rowOrganizations["organization_id"]){ print "selected";} . " value=' . $rowOrganizations["organization_id"] . '>" . $rowOrganizations["organization"] . "</option>"; 
     }
     echo "</select>";
}

Viewing all articles
Browse latest Browse all 13200

Trending Articles