I have a silly issue,

I am creating a CMS at the moment. it has pages and menus .

I created a page to add new pages. on that page i have a drop down list that is populated with data from the menu.

I also have an edit page, on this page i want to pull in the current value from the database into a drop down and be able to change the value.

Can anyone help

I have a silly issue,

I am creating a CMS at the moment. it has pages and menus .

I created a page to add new pages. on that page i have a drop down list that is populated with data from the menu.

I also have an edit page, on this page i want to pull in the current value from the database into a drop down and be able to change the value.

Can anyone help

To fetch values from db into a drop down u can use this...

$query = "SELECT fieldname FROM tablename" ;
$result = mysql_query($query);
echo'<select name="somename">';
while($row = mysql_fetch_assoc( $result )) { 
        echo '<option value="'.$row['fieldname'].'">' . $row['fieldname'] . '</option>';   
}
echo '</select>';

I didnt test it but it must be more or less correct...
cheers!

To fetch values from db into a drop down u can use this...

$query = "SELECT fieldname FROM tablename" ;
$result = mysql_query($query);
echo'<select name="somename">';
while($row = mysql_fetch_assoc( $result )) { 
        echo '<option value="'.$row['fieldname'].'">' . $row['fieldname'] . '</option>';   
}
echo '</select>';

I didnt test it but it must be more or less correct...
cheers!

Hi, i can pull the data from the db thats not the issue. i cant retrieve the current value stored in the db. this is the code i am using:

$query="SELECT name,menu_id FROM menus";
						$result = mysql_query ($query);
						echo "<select name=menu_name value=''>Menu Name</option>";
						while($menu=mysql_fetch_assoc($result)){
						echo "<option value=$menu[menu_id]>$menu[name]</option>";
						}
						echo "</select>";

Hi, i can pull the data from the db thats not the issue. i cant retrieve the current value stored in the db. this is the code i am using:

$query="SELECT name,menu_id FROM menus";
						$result = mysql_query ($query);
						echo "<select name=menu_name value=''>Menu Name</option>";
						while($menu=mysql_fetch_assoc($result)){
						echo "<option value=$menu[menu_id]>$menu[name]</option>";
						}
						echo "</select>";

What do you mean by current value? Is it a separate field stored in the db? Could u please be more clear about what are u trying to do here... n if u can provide menus table structure that would b gr8..
The code u pasted is fine and that would display a drop down with all the menus currently in db. What are u looking to do with that..?

btw the line

echo "<select name=menu_name value=''>Menu Name</option>";

appears to be wrong... if u r trying to display "Menu Name" as an option, u have to first open <option> tag

echo "<select name=menu_name value=''><option>Menu Name</option>";

Hi venkat!!

Thanks dear this is what i was looking for ...made by day
Thanks once again..Keep it Up!!
Pavan

Hi venkat!!

Thanks dear this is what i was looking for ...made by day
Thanks once again..Keep it Up!!
Pavan

Good to know it helped.. cheers!!

how can i display the record related to value from select option...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.