Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

php mysql option box question

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Fri Nov 09, 2007 8:33 am    Post subject: php mysql option box question Reply with quote

I have an option box that i have several options in. What i want to do is be able to have it select the one that is in the database.

So the options are

Now, Later, Before

and in the database the field is called time

I want it to be automatically selecting the correct one, how do i go about this?
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4619
Location: Down Under

PostPosted: Fri Nov 09, 2007 5:18 pm    Post subject: Reply with quote

Loop over the options and add selected attribute to the appropriate one. Assuming interspersed HTML:
Code:
$options = array('Now', 'Later', 'Before');
$current = 'Now';
echo '<select>';
foreach ($options as $k=>$v)
  echo '<option value="'.$v.'"'.($v==$current ? 'selected="selected"' : '').'>'.$v.'</option>';
echo '<select>';
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Sat Nov 10, 2007 5:05 am    Post subject: Reply with quote

thanks, works perfectly
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com