SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echoing users data from mysql

    Hi Guys,

    when users on my site look at they're profile details some of the data in like this:

    PHP Code:
    <select name="somename">
    <
    option value="Option 1">Option 1</option>
    <
    option value="Option 2">Option 2</option>
    </
    select
    once a user has selected an option and it's stored in mysql, i was wanting the specific information to be displayed in the drop down box, if i selected option 2 next time i log in option 2 is displayed and so on.

    what would be the best way to achieve this?

    thanks guys

    Graham

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Graham,

    When you loop through the available values creating your selection list use an if clause to check the returned value against the users value, if they are the same then in the option tag echo selected option selected="selected">
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mate,

    kinda like this:

    PHP Code:
    <select name="somename">
    <
    option value="Option 1">Option 1</option>
    if(
    somename == $somename) {

    echo 
    "<option value="Option 1">$somename</option>";

    }
    <
    option value="Option 2">Option 2</option
    </
    select
    is that along the correct lines mate?

    thanks

    Graham

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    ?>
    <select name="this_field">
    <?php
    while ( $row=mysql_fetch_assoc$results ) {
        if ( 
    $Users_Data_Value == $row['Field_to_Compare']) {
            echo 
    "<option value=\"Option 1\" selected=\"selected\">Option 1</option>";
        } else {
            echo 
    "<option value=\"Option 2\">$Option 2</option>"
        }
    }
    ?>
    </select>
    <?php
    More like this Graham.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help mate

    Graham

  6. #6
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My pleasure...

    Byron
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


Bookmarks

Posting Permissions

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