28, May 2012

auto select dropdown from database? - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: auto select dropdown from database?
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: auto select dropdown from database?  (Read 2130 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« on: Aug 08, 2006, 06:04:31 pm »

as you all should know by now, im quite a n00b at PHP, im a beginner, and i barely know the basics as it is.. but im having this problem.. i have modified php fusion (even further than I have mentioned before) and now, you can have a special rank, well this is an ID# from the database for each user, say if they have user_clanrank = 3, their rank is leader or something.. well.. when i go to the admin panel to update their rank, that drop down menu from where you select their rank is always RESET so if you dont change it back each time, it will change it in the DB. any idea how to make it select your current rank automatically?

Code:
echo "
<tr>
<td class='tbl'>Clan Rank:</td>
<td class='tbl'>";
echo "
<select size='1' name='user_clanrank' class='textbox'>
<option selected>Choose One</option>
<option value='1'>Public User</option>
<option value='2'>Inactive Member</option>
<option value='3'>Trial Member</option>
<option value='4'>Clan Member</option>
<option value='5'>Event Coordinator</option>
<option value='6'>Elite</option>
<option value='7'>Emissary</option>
<option value='8'>Legendary Member</option>
<option value='9'>Board of Advisory</option>
<option value='10'>Overseer</option>
<option value='11'>Kingpins Aide</option>
<option value='12'>Kingpin</option>
<option value='13'>Clan Friend</option>
<option value='14'>Trusted Clan Friend</option>
<option value='15'>Allied Clan Member</option>
</select>";


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Aug 08, 2006, 11:46:47 pm »


I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Aug 09, 2006, 10:04:31 am »

Or you can use an associative array, like this:

Code:
<?php
$values 
= array(
  
=> 'Public User',
  
=> 'Inactive Member',
  
=> 'Trial Member'
);

This array should have all the possible values. Then if for example you have store the user's rank in a variable called $rank, you can do this :

Code:
<?php
foreach ( $values as $id => $r )
{
 echo 
'<option value="'.$id.'"'.($id==$rank?' selected':'').'>'.$r.'</option>';
}

Hope that helps Wink

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Aug 09, 2006, 10:07:43 am »

Quote
Hope that helps Wink

important is that the current value from the database is selected during form submission.

aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #4 on: Aug 09, 2006, 11:30:57 pm »

ok thx everyone for the responses, im gonna try your method first Nik, will post here if i have any more issues


god i love this forum..


Last blog : phpHaze 1.59.1 in Development
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #5 on: Aug 10, 2006, 06:35:39 am »

here is my completed version of the snippet to do this, and it worked first try. thanks alot nik, tell me if this is right though:

Code:
<?php echo "
<tr>
<td class='tbl'>Clan Rank:</td>
<td class='tbl'>"

$values = array(
  1 => 'Public User',
  2 => 'Inactive Member',
  3 => 'Trial Member'
  4 => 'Clan Member',
  5 => 'Event Coordinator',
  6 => 'Elite',
  7 => 'Emissary',
  8 => 'Legendary Member',
  9 => 'Board of Advisory',
  10 => 'Overseer',
  11 => 'Kingpins Aide',
  12 => 'Kingpin',
  13 => 'Clan Friend',
  14 => 'Trusted Clan Friend',
  15 => 'Allied Clan Member',
);
echo 
"
<select size='1' name='user_clanrank' class='textbox'>"
;
foreach ( 
$values as $id => $r )
{
 echo 
'<option value="'.$id.'"'.($id==$data['user_clanrank']?' selected':'').'>'.$r.'</option>';
}
echo 
"</select>"?>


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #6 on: Aug 10, 2006, 12:43:55 pm »

It seems that you have learned php in the months past meth0d Smiley

The code you posted needs a small correction, here is the right one:

Code:
<?php echo "
<tr>
<td class='tbl'>Clan Rank:</td>
<td class='tbl'>"

$values = array(
  
=> 'Public User',
  
=> 'Inactive Member',
  
=> 'Trial Member'
  
=> 'Clan Member',
  
=> 'Event Coordinator',
  
=> 'Elite',
  
=> 'Emissary',
  
=> 'Legendary Member',
  
=> 'Board of Advisory',
  
10 => 'Overseer',
  
11 => 'Kingpins Aide',
  
12 => 'Kingpin',
  
13 => 'Clan Friend',
  
14 => 'Trusted Clan Friend',
  
15 => 'Allied Clan Member'
);
echo 
"
<select size='1' name='user_clanrank' class='textbox'>"
;
foreach ( 
$values as $id => $r )
{
 echo 
'<option value="'.$id.'"'.($id==$data['user_clanrank']?' selected':'').'>'.$r.'</option>';
}
echo 
"</select>"?>


Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #7 on: Aug 10, 2006, 05:57:07 pm »

ok if possible can you explain why you made that change and what difference it makes? curious Smiley this is how i learn

edit: looking at what you did i dont even see a change ;o
« Last Edit: Aug 10, 2006, 05:59:35 pm by Meth0d »


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Aug 10, 2006, 06:00:20 pm »

ok if possible can you explain why you made that change and what difference it makes? curious Smiley this is how i learn

edit: looking at what you did i dont even see a change ;o
me too Cheesy

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #9 on: Aug 10, 2006, 06:03:34 pm »

In the end of the array statement you had an extra ,

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #10 on: Aug 10, 2006, 06:12:13 pm »

In the end of the array statement you had an extra ,
yes all this small thinks more bad is a almost invisble "backtick"

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #11 on: Aug 10, 2006, 06:14:50 pm »

In the end of the array statement you had an extra ,
yes all this small thinks more bad is a almost invisble "backtick"

I remember countless times searching why the script is not working, and you finally find that , ........ Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #12 on: Aug 10, 2006, 06:20:22 pm »

yes me too, place for the backtick "`" in a php script there error is much more fun

aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #13 on: Aug 10, 2006, 06:58:31 pm »

ah ok, tyvm for the help on this one Smiley


Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3586
Tags : php forums databases snippets Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: auto select dropdown from database?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 02:54:27 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.