How to display only one member photo of a login user?

Discussion in 'PHP' started by ketting00, Nov 26, 2009.

  1. #1
    Hi,

    I have created a web site with member login system. It's looking good. It allow a login user to upload their photos and display one of them as profile picture.

    But when I retrieve the uploaded photo with these codes: it displays all the photos anyone have uploaded.

    // Display Member Profile Picture
    if (!isset($_SESSION['memberpix'])) {
    while($row = mysql_fetch_array( $result)) {
    echo "<img src='photos/" . $row['pixpath'] . "'>";
    }
    } else {

    echo "<img src='photos/nopic.jpg'>";
    }

    How could I resolve the problem?

    Thanks in advance
     
    ketting00, Nov 26, 2009 IP
  2. flakas123

    flakas123 Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't use loop if you want to retrieve only a single item from DB. I suggest you to use this:
    echo "<img src='photos/".@current(@mysql_fetch_assoc($result))."'>";
    instead of this:
    while($row = mysql_fetch_array( $result)) {
    echo "<img src='photos/" . $row['pixpath'] . "'>";
    }

    However it would be a good idea to check if user has uploaded any photos :)
     
    flakas123, Nov 26, 2009 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #3
    Thanks for swift response,

    I'll go check if it works???
     
    ketting00, Nov 26, 2009 IP
  4. flakas123

    flakas123 Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah.. one more thing.
    My previous code might not work. It depends on how you form the query. If you select only one column - it will work, however if you select multiple columns, you might have to slightly alter my code to:
    $row = @mysql_fetch_assoc($result);
    echo "<img src='photos/".$row['pixpath']."'>";
     
    flakas123, Nov 26, 2009 IP
  5. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #5
    Here the former codes:

    $result = mysql_query("SELECT * FROM memberpix WHERE pixid=''") or die(mysql_error());

    thanks
     
    ketting00, Nov 26, 2009 IP
  6. flakas123

    flakas123 Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yep, this should work:

    $row = @mysql_fetch_assoc($result);
    echo "<img src='photos/".$row['pixpath']."'>";
     
    flakas123, Nov 26, 2009 IP