Valuate Domain Names
DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
HomeRegisterMembershipsGetting StartedDomain Tools Domain EbooksSEO Software Domain Resellers Advertise

Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Register Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 03-20-2009, 07:28 AM   #1 (permalink)
Platinum Lifetime Member
 
MrDude's Avatar
 
Name: Paul Rogers
Last Online: 09-26-2009 07:44 AM
iTrader: (10)
Join Date: Jun 2005
Posts: 1,251
DNF$: 0
Location: UK
Country:


PHP/MySQL setting selected option for Dropdown Menu

I always see it on forums and stuff, when you go to edit your profile, your date of birth or whatever you put in a dropdown menu is shown to you, exactly how you selected it.

I have a form where people enter their date of birth, location etc, and I want it so when they go to edit, they see their selections already selected in the dropdown list by adding selected='selected' to it, I really cant figure out how to do it, and my only workaround right now is to add a duplicate at the top of the dropdown list.
MrDude is offline   Reply With Quote
Sponsored Ads
Old 03-20-2009, 07:55 AM   #2 (permalink)
DNF Addict
 
south's Avatar
 
Name: Scott
Last Online: Today 01:10 PM
iTrader: (133)
Join Date: Dec 2006
Posts: 3,079
DNF$: 2,451
Location: 33143/04930
Country:


I don't fully understand the question, but I'm guessing you are looking for a script that will populate a form based on the drop down menu?

Try this to get some ideas: http://www.codingforums.com/showthread.php?t=80345
__________________
All offers valid for 72 hours except running auctions.

SJCParking.com | PrivateNursing.net | LaGuardiaParking.net

Last edited by south; 03-20-2009 at 08:03 AM..
south is offline   Reply With Quote
Old 03-20-2009, 08:09 AM   #3 (permalink)
Missing in action
 
sdsinc's Avatar
 
Name: Kate
Last Online: Today 05:26 PM
iTrader: (41)
Join Date: Jul 2005
Posts: 4,626
DNF$: 27,483
Location: front line
Country:


Here is one example.

The idea is that when the form loads, you retrieve their saved data from the DB. Let's just fetch their year of birth as an example.
Then you build your combo using a loop (here current year = 2009 through 1909). The year that matches your variable gets the selected attribute.

PHP Code:
<?php
$link
=mysql_pconnect("localhost","user","password");
mysql_select_db("db",$link);
$result mysql_query("select date_format(birth_date,'%Y') as birth_year from members where member_id=1");

$row=mysql_fetch_array($result); // fetch first row
$year=$row["birth_year"]; // retrieve 4-digit year of birth

// display combo: current year -> -100
$current_year=date("Y");
echo 
'<select name="cbo_year">';
for (
$i $current_year$i >= ($current_year-100); $i--) {
echo 
'<option '.($year == $i ' selected ' '').' value="'.$i.'" >'.$i.'</option>';
}
echo 
'</select>';
?>
For XHTML compliant code use this instead
PHP Code:
echo '<option '.($year == $i ' selected="selected " ' '').' value="'.$i.'" >'.$i.'</option>'
__________________
VeryOldNames.com
sdsinc is online now   Reply With Quote
Old 03-20-2009, 09:53 AM   #4 (permalink)
Platinum Lifetime Member
 
MrDude's Avatar
 
Name: Paul Rogers
Last Online: 09-26-2009 07:44 AM
iTrader: (10)
Join Date: Jun 2005
Posts: 1,251
DNF$: 0
Location: UK
Country:


Thankyou!

That was exactly what I was looking for with regards to their date of birth, but my biggest pain is Location of the users, with a long dropdown list is there an easy way about it? Its not really important, im just looking to have things working properly, if its too much hassle for me I may just duplicate their location such as "United States" at the top of the list.
MrDude is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:09 PM.
Copyright @2001-2009 DNForum.com