IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Editing Drop Down Menu In Php


apple
no avatar
Newbie [Level 2]
**
Group: Members
Posts: 32
Joined: 9-August 06
Member No.: 28,049



Post #1 post Apr 25 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>


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.
Go to the top of the page
+Quote Post
Saint_Michael
no avatar
$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
*********************
Group: [MODERATOR]
Posts: 7,255
Joined: 21-September 04
From: 9r33|\| 399$ 4|\|D 5P4/\/\
Member No.: 1,218
myCENT:83.20



Post #2 post Apr 26 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.thesitewizard.com/wizards/navigationmenu.shtml

This is a script that creates a dhtml drop down menu

http://www.scriptdungeon.com/script.php?ScriptID=1010

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

http://www.phpclasses.org/browse/package/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"
Go to the top of the page
+Quote Post
galexcd
no avatar
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********
Group: [MODERATOR]
Posts: 1,316
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:59.43



Post #3 post May 12 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:

CODE
<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:
CODE
<?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>
Go to the top of the page
+Quote Post
hitmanblood
no avatar
Privileged Member
*********
Group: [HOSTED]
Posts: 786
Joined: 13-April 07
From: mreža
Member No.: 41,558



Post #4 post May 18 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.

CODE
<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>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new 17 holyium 8,370 1st January 2005 - 10:08 AM
Last post by: hulunes
No New Posts   1 neeki4444 5,365 18th March 2005 - 02:25 AM
Last post by: andrewsmithy
No New Posts   1 misterhh 982 8th August 2007 - 08:47 AM
Last post by: truefusion
No New Posts   6 YSR 2,028 16th December 2008 - 07:59 PM
Last post by: minimcmonkey
No New Posts   3 --Stealth-- 2,099 6th March 2008 - 06:57 PM
Last post by: FeedBacker
No New Posts   6 SmUX 3,300 21st December 2004 - 02:14 AM
Last post by: chiclete
No New Posts   1 desimela 4,976 7th December 2004 - 01:54 AM
Last post by: icedragn
No New Posts   3 techfreakorama 1,224 29th March 2009 - 09:57 AM
Last post by: flashy
No New Posts 11 karlo 7,719 23rd January 2005 - 04:29 PM
Last post by: popac
No New Posts   0 thablkpanda 3,839 5th February 2005 - 09:02 PM
Last post by: thablkpanda
No New Posts   1 guangdian 2,271 13th February 2005 - 07:05 AM
Last post by: guangdian
No New Posts   2 miCRoSCoPiC^eaRthLinG 2,257 2nd July 2005 - 05:31 PM
Last post by: miCRoSCoPiC^eaRthLinG
No New Posts   1 carrot 1,523 5th March 2005 - 04:21 AM
Last post by: canute24
No New Posts   4 alexia 3,956 8th March 2005 - 05:23 AM
Last post by: karlo
No New Posts   2 nickmealey 3,518 29th May 2008 - 06:09 AM
Last post by: FeedBacker


 



RSS Open Discussion Time is now: 8th November 2009 - 12:51 PM

Web Hosting Powered by ComputingHost.com.