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 November 6th, 2003, 02:15 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
select form box remember data!

okay I can't figure out how to do this (I guess that's obvious eh). well i have some forms which a user enters info, it is put into the database, and then the user can go back and edit it. But some of it is in select boxes (like birthdate). Now I can't figure out how to make the value in the database be put into the box, and this is especially annoying if a user wants to edit some things but not the drop box, it makes the drop box whatever is teh normal first value. for the birthday I did this:

this is just for year
PHP Code:
<select name="strYear">
        <?
php if($IsLoggedIn)
                { 
?>
        <option Selected><?php echo $year?></option>
        <?php } else { ?>        
          <option>Year</option>
          <?php ?>
          <option>-----</option>
          <?php 
      $yearValue 
1980;
      while(
$yearValue <= 2003)
      {
      
$yearValue $yearValue 1;?>
          <option><?php echo $yearValue?></option>
          <?php ?>
        </select> 


this basically jsut makes the top value the value they entered... can i get it to jsut center in on that value in my normal list? is there a better way to do this?
thanks
__________________
hey it's the CHARKING

Reply With Quote
  #2  
Old November 6th, 2003, 02:29 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Try this:

PHP Code:
<select name="strYear">
<?
php
for($i=1980$idate('Y'); $i++){
    
$selected=(($i==$year)?" selected":"");
    print 
"<option value=\"" $i "\"" $selected ">" $i "</option>\n";
}
?>
</select> 

Reply With Quote
  #3  
Old November 7th, 2003, 02:35 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
thank you! that works really well! I was wondering, in the case of text and not numbers, how would it be done? such as my month, it is sort of a long part of my script. I was wondering maybe you could even just comment that other code, so I could see exactly what it all does, cause I'm still pretty new. Thank you. And be expecting a pm! haha

Reply With Quote
  #4  
Old November 7th, 2003, 03:48 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
PHP Code:
<select name="strYear">
<?
php
//Here I'm using the current date rather than hard-coding it as you had. 
//Reduces maintenance issues down the road b/c you won't have to remember to edit the year each new year.

for($i=1980$idate('Y'); $i++){
    
//Ternary operator here:
    //Evaluates $i==$year
        //If true, return part after ?
        //Else return the part after the colon
        //This is just a shorthand way of doing an if-else statement.
        //Basically, if the values match, we're returning the string " selected" and inserting it into the option tag. Else we're inserting nothing.
    
$selected=(($i==$year)?" selected":"");
    print 
"<option value=\"" $i "\"" $selected ">" $i "</option>\n";
}
?>
</select> 


You should be able to use the code with text or numbers. If you're using text, you'd want to create an array of possible text values and pass that to the for statement like so:

PHP Code:
<?php

for($i=0$i<sizeof($textarray); $i++){
    
$selected=(($textarray[$i]==$databasevalue)?" selected":"");
    print 
"<option value=\"" $textarray[$i] . "\"" $selected ">" $textarray[$i] . "</option>\n";
}

?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > select form box remember data!


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 6 hosted by Hostway
Stay green...Green IT