General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 20th, 2003, 08:51 PM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
Selects being Selected Dynamically

Hey all,

Alright, I have a list of countries, and what I want to do, is when the person goes to edit their profile. I want the list to have their country selected (the country is stored in the database). Any ideas? Thanks.

Reply With Quote
  #2  
Old July 20th, 2003, 11:59 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Are your select lists being generated dynamically also?
Do you also need help generating the select county list from the database or do you have that part covered already?

The methods for doing this are different depending on whether your list is created dynamically or statically.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old July 21st, 2003, 01:23 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Ya - as laidback has said. To get you partially started, you would (of course) have to have the country id from the users profile to do the conditional on that. The conditional would look something like this:
PHP Code:
if ( $user_profile_country_id == $the_drop_down_country_id )
{
        echo( 
'<option value="the_value" selected>The Name</option>' );
}
else
{
        echo( 
'<option value="the_value">The Name</option>' );

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #4  
Old July 21st, 2003, 01:53 AM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
The country list is static, but I'm thinking about transferring it to a database with flags and timezone offsets and stuff. Would this be easier to do if it were dynamic?

If it were dynamic, i was thinking of doing something like
PHP Code:
 $r "";
$ucountry mysql_fetch_array(mysql_query("SELECT CountryList.* FROM CountryList LEFT JOIN UserList ON UserList.countrycode = CountryList.countrycode WHERE UserList.uid = '$uid'"));
$r .= "<option value=\"$ucountry['code']\">$ucountry['name']</option>\n";
$ocountry mysql_fetch_array(mysql_query("SELECT CountryList.* WHERE CountryList.countrycode != '" $ucountry['code'] . "'");
foreach(
$ocountry as $country){
$r .= "<option value=\"$country['code']\">$country['name']</option>\n";
}
echo(
"<select name=\"country\">");
echo(
$r);
echo(
"</select>"); 


There might be some parse errors in there, but I can clean that up. Is that the basic idea though?

Reply With Quote
  #5  
Old July 21st, 2003, 02:11 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Yes - but you still need to put the conditional in there to echo 'selected' when the condition is true.

Reply With Quote
  #6  
Old July 21st, 2003, 02:14 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Yes, you have the general idea. That is how you would put it together dynamically. Just look at jpenn's if statement and that is how you would have the correct value automatically selected upon page load.


Doing it statically works pretty good too, but the only issue there is that you would always have two entries of the item that is selected. (you would just have a php statement to have that option written to the top of the select element and give it the SELECTED attribute).

Reply With Quote
  #7  
Old July 21st, 2003, 02:17 AM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
Well, this way I have it so it selects the persons country (as via the first query) then adds the rest of the countries under it (Via the second query)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Selects being Selected Dynamically


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT