Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Jer
    Jer is offline
    New Coder
    Join Date
    Aug 2010
    Location
    South Bend, Indiana
    Posts
    41
    Thanks
    2
    Thanked 1 Time in 1 Post

    Using select to update profile...

    PHP Code:
    $userdata mysql_query("SELECT * FROM user_data WHERE id='$id'");
    $row mysql_fetch_array($userdata);

    $timezone=$row['time_zone']; 
    That pulls an int to relate to my timezone table.

    PHP Code:
    print "<select name='' style='width: 157px'>";
    $sql mysql_query("SELECT * FROM timezone");
    while (
    $row mysql_fetch_array($sql)) {
    print 
    "<option value={$row['timezone_id']}>{row['timezone_name']}</option>";
    }
    print 
    "</select>"
    I have no errors and the list populates correctly.

    What I want it to do is show the option as the original value in the <select> coding. So if my user has record 24 which is EST+5GMT that is what option is shown already selected in that box. This is for an edit page of a user profile.

    Apologies I'm trying to do this on a phone since I'm at work.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Change
    PHP Code:
    while ($row mysql_fetch_array($sql)) {
    print 
    "<option value={$row['timezone_id']}>{row['timezone_name']}</option>";

    to
    PHP Code:
    while ($row mysql_fetch_array($sql)) {

    printf"<option value={$row['timezone_id']} %s>{row['timezone_name']}</option>",
    (
    $row['time_zone']==$row['timezone_id']?'selected="selected"':''));

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Jer (10-20-2010)

  • #3
    Jer
    Jer is offline
    New Coder
    Join Date
    Aug 2010
    Location
    South Bend, Indiana
    Posts
    41
    Thanks
    2
    Thanked 1 Time in 1 Post
    Still didn't select properly, but you may have pointed me in the correct direction.

  • #4
    Jer
    Jer is offline
    New Coder
    Join Date
    Aug 2010
    Location
    South Bend, Indiana
    Posts
    41
    Thanks
    2
    Thanked 1 Time in 1 Post
    PHP Code:
    printf"<option value={$row['timezone_id']} %s>{$row['timezone_name']}</option>",
    (
    $timezone==$row['timezone_id']?'selected="selected"':'')); 
    Just a change in variables. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •