lovephp Posted July 10, 2014 Share Posted July 10, 2014 friend the code display all the managers name <?php echo '<select name="Manager">'; $query="SELECT * FROM managers"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['manager_name'] . "'>" . $row['manager_name'] . "</option>"; } echo '</select>'; ?> and the variable below displays the result $Manager= $row['Manager'] ; but how do i do it on the above dropdown list the it shows which result is in the $Manager variable? Quote Link to comment https://forums.phpfreaks.com/topic/289655-how-to-show-selected-result-from-db-on-dropdown/ Share on other sites More sharing options...
cyberRobot Posted July 10, 2014 Share Posted July 10, 2014 You could try something like this: <?php echo '<select name="Manager">'; $query="SELECT * FROM managers"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "<option value='{$row['manager_name']}'"; if($Manager == $row['manager_name']) { echo ' selected="selected"'; } echo ">{$row['manager_name']}</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/289655-how-to-show-selected-result-from-db-on-dropdown/#findComment-1484505 Share on other sites More sharing options...
mogosselin Posted July 10, 2014 Share Posted July 10, 2014 I'm not sure I understand what you mean. Is the code you posted working or not? If it's not working, what does it do? And why do you want to use $row['Manager']? What's inside the brackets [] is supposed to be the name of a column coming from a table in your Database. Do you have column namde 'Manager' in your 'Managers' table? If its the case (but I doubt it, but whatever, I'll take the guess), then your code would need to be like this: echo "<option value='" . $row['Manager'] . "'>" . $row['Manager'] . "</option>"; OR $Manager = $row['Manager']; echo "<option value='" . $Manager . "'>" . $Manager . "</option>"; seems like what you asked for, but I'm not sure it makes sense Quote Link to comment https://forums.phpfreaks.com/topic/289655-how-to-show-selected-result-from-db-on-dropdown/#findComment-1484506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.