Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Editing Drop Down Menu In Php


4 replies to this topic

#1 apple

    Newbie [Level 2]

  • Kontributors
  • PipPip
  • 32 posts

Posted 25 April 2007 - 11:35 PM

suppose i make a dropdown menu having value 1, 2, 3, 4, 5, one option can be selected, and selected option is stored in database.
now i create an edit page, how do i display the selected value in the menu and other values in dropdown,
for example,
Menu is like
Select One
1
2
3
4
5

and i select 3, this 3 is stored in database, now on the edit page i want to show 3 as already selected,
something like that..


[quote]<select name="select_thing">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3" selected>3</option>
	<option value="4">4</option>
	<option value="5">5</option>
</select>[/quote]
I will be very thankful, if someone could help by explaining how do i make option 3 as selected.. eg. how i know option 3 is selected and stored in db.

Edited by moderator, 21 April 2012 - 11:20 AM.


#2 Saint_Michael

    $p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 7,459 posts
  • Gender:Male
  • Location:9r33|\| 399$ 4|\|D 5P4/\/\
  • Interests:$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
  • myCENT:71.24

Posted 26 April 2007 - 12:54 AM

Here are some links to help you out.

This is a wizard that designs a php drop down menu

http://www.thesitewi...ationmenu.shtml

This is a script that creates a dhtml drop down menu

http://www.scriptdun...p?ScriptID=1010

This site talks about what goes into a php drop down menu and provides files as well

http://www.phpclasse...ckage/1562.html

Hopefully that helps give you an idea on what to look for in designing a php drop down menu

GOOGLE KEYWORDS

"drop down menu in php"

#3 galexcd

    Trap Grand Marshal Member

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,331 posts
  • Gender:Not Telling
  • myCENT:39.82

Posted 12 May 2007 - 07:02 PM

Couldn't you just make an if statement? If you know how to get and set the values in the database already, all you'd have to do is somthing like:

<select name="select_thing">
<option value="1"<?php
if(mysql_result($result,"","value")==1) echo" selected";
?>>1</option>
<option value="2"<?php
if(mysql_result($result,"","value")==2) echo" selected";
?>>2</option>
<option value="3"<?php
if(mysql_result($result,"","value")==3) echo" selected";
?>>3</option>
<option value="4"<?php
if(mysql_result($result,"","value")==4) echo" selected";
?>>4</option>
<option value="5"<?php
if(mysql_result($result,"","value")==5) echo" selected";
?>>5</option>
</select>


If that's what you meant, here's a more code-conserving way of writing it:
<?php ${mysql_result($result,"","value)}=" selected";?>
<select name="select_thing">
<option value="1"<? echo $1 ?>>1</option>
<option value="2"<? echo $2 ?>>2</option>
<option value="3"<? echo $3 ?>>3</option>
<option value="4"<? echo $4 ?>>4</option>
<option value="5"<? echo $5 ?>>5</option>
</select>


#4 hitmanblood

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 788 posts
  • Gender:Male
  • Location:mreža

Posted 18 May 2007 - 08:00 PM

OK this solution will work also I encourage you to try it it looks more simple to me then others. I cannot tell is it because I use it and I am familiar with it or just because it is simpler then other.

Good luck with whatever you are doing

For the script I think that it doesn't need any more explanation also I would like to point out that I took in count that when you have loaded this value from your database that then you have saved it in the initial_var that is initial variable.

<select name="testlist">
  <option <? if(initial_var == "1"){ echo 'selected'; } >?  >1</option>
  <option <? else if(initial_var == "2"){ echo 'selected'; } >? >2</option>
  <option <? else if(initial_var == "3"){ echo 'selected'; } >? >3</option>
  <option <? else if(initial_var == "4"){ echo 'selected'; } >? >4</option>
  <option <? else{ echo 'selected'; } >? >5</option>
  </select>


#5 Guest_prajakta_*

  • Guests

Posted 08 December 2011 - 05:28 AM

i have not fired a query from which i can get $result....do u have any other solution?plss help me out




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users