Drop down.

Discussion in 'PHP' started by CPAPubMichael, Jan 16, 2011.

  1. #1
    Hello,

    I need some help, i have been trying at this for days and found no possible way.

    I have a drop down:

    
    
    <select name="payMethod" tabindex="10">
     <option value="AlertPay">AlertPay</option>
     <option value="Check">Check</option>
     <option value="PayPal">PayPal</option>
    </select>
    
    
    HTML:
    I know Drop Downs cannot hold values like an input box.

    So what i need help with is how to get the selection drop down to hold a value from the database.

    Please help as i have been trying this for days.

    Thank you very much for you time, it is much appreciated.

    Michael
     
    CPAPubMichael, Jan 16, 2011 IP
  2. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Basically i am creating an Edit Account page. I need that selection box to hold a value.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 16, 2011 IP
  3. OMMCompany

    OMMCompany Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    echo '<select name="yada">';
    $query = mysql_query("SELECT * FROM categories");
    if (mysql_num_rows($query) > 0)
    {
       while ($list = mysql_fetch_array($query))
       {
             echo '<option value="'.$list['name'].'">'.$list['name'].'</option>';
       }
    }
    else
    {
       echo '<option value="">There are no selection options.</option>';
    }
    echo '</select>';
    
    PHP:
     
    OMMCompany, Jan 16, 2011 IP
  4. BreezeTR

    BreezeTR Well-Known Member

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #4
    (if I understood your question correctly)
    after you assign dbvalue :

    <select name="payMethod" tabindex="10">
    <option value="AlertPay" <?php if (db_value=="AlertPay") echo ("selected=selected"); ?> >AlertPay</option>
    <option value="Check" <?php if (db_value=="Check") echo ("selected=selected"); ?> >Check</option>
    <option value="PayPal" <?php if (db_value=="PayPal") echo ("selected=selected"); ?> >PayPal</option>
    </select>
     
    BreezeTR, Jan 16, 2011 IP
  5. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I think i explained it wrong to you.

    I need it to maintain there value what they made prior to Sign up. Say they selected PayPal in the database, it will then have PayPal selected in the drop down among all the others.

    Thank you any way,

    Michael
     
    CPAPubMichael, Jan 16, 2011 IP
  6. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You need to render selected attribute when rendering inside the for loop.

    Final output would be:
    
    <select name="payMethod" tabindex="10">
     <option value="AlertPay">AlertPay</option>
     <option value="Check">Check</option>
     <option selected="selected" value="PayPal">PayPal</option>
    </select>
    
    Code (markup):
     
    hogan_h, Jan 16, 2011 IP
  7. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you very much. That worked.
     
    CPAPubMichael, Jan 16, 2011 IP
  8. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks... just noticed. Lol
     
    CPAPubMichael, Jan 16, 2011 IP
  9. BreezeTR

    BreezeTR Well-Known Member

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #9
    Not al all.
     
    BreezeTR, Jan 16, 2011 IP