0

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

4
Contributors
6
Replies
35
Views
7 Years
Discussion Span
Last Post by sachin.padole1
0

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!

Edited by venkat0904: n/a

0

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>";
0

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>";

Edited by venkat0904: n/a

0

Hi venkat!!

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

0

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!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.