Need help with using PHP to dynamically retain a selected value from a HUGE list.

Discussion in 'PHP' started by Sapphiro, Apr 25, 2009.

  1. #1
    Hi people, really need help here.

    Here's the situation:

    I've got a registration page with a dropdown list of more than 300 records, and there are also other input fields as well, and the user will be returned back to the registration page if there are any missing input field (which means it wont pass the validation).

    What I want is to have all of the already entered values to be retained on the registration page so that the user wont have to spend too much more time filling them up again. I have no problem with this with textboxes, but as for the dropdown menu, there's a huge problem.

    Basically this is the best code that I think I could use so far:
    <option VALUE="A"<?php if($_SESSION['Variable'] =="A"){ echo "A";} ?>>A</option> 
    Code (markup):
    but as you can see, there are more than 300 records, I don't wish to manually enter the variable inside, it'd be the best if there's any algorithm which works kinda like this (so I can just use them for any option:
    <option value="bla" <?php checkifselected(this.option.value) ?>bla bla</option>
    Code (markup):
    If anyone knows of a similar code, would you mind sharing with me? :eek:
     
    Sapphiro, Apr 25, 2009 IP
  2. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #2
    does your record come from a database?
     
    creativeGenius, Apr 25, 2009 IP
  3. Sapphiro

    Sapphiro Well-Known Member

    Messages:
    1,242
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    175
    #3
    hmm not for this, but I'm using session to return it from the validator page
     
    Sapphiro, Apr 26, 2009 IP
  4. Sapphiro

    Sapphiro Well-Known Member

    Messages:
    1,242
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    175
    #4
    Hi all, I solved this problem myself, so I don't need anymore help already. :)
     
    Sapphiro, Apr 26, 2009 IP
  5. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #5
    glad to hear that :)

    regards
     
    ghprod, Apr 27, 2009 IP