Jump to content

[SOLVED] Populating drop down menu


BenProl

Recommended Posts

Hi all,

 

I've been looking at PHP for about a week so apologies in advance for any poor form...

 

I'm building a form for editing page content. It's pretty simple, a moderator clicks on the page that they want to edit and the form fields are then pre-populated with the page data from the database. I've managed to achieve this for every field apart from the drop-down menu.

 

Obviously, I need the pre-selected option to be the correct one, but right now it isn't populating the menu at all.

 

<select name="subject_id" id="subject_id" tabindex="1">

     

<?php
	$locations_query = "SELECT * FROM vacancy_locations ORDER BY position ASC";
	$locations_set = mysql_query($locations_query, $connection);
	confirm_query($locations_set);
	while ($location_data = mysql_fetch_array($locations_set)) {
		echo "<option value='{$location_data["menu_name"]}'";
		if ($pg_data['subject_id'] == $location_data['id']) { 
				echo " selected";
			} }
		echo "></option>";
  ?>

    </select>

 

Any help?

 

Many thanks,

 

BenH

Link to comment
https://forums.phpfreaks.com/topic/78912-solved-populating-drop-down-menu/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.