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
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
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']."'>";
Here the former codes: $result = mysql_query("SELECT * FROM memberpix WHERE pixid=''") or die(mysql_error()); thanks
Yep, this should work: $row = @mysql_fetch_assoc($result); echo "<img src='photos/".$row['pixpath']."'>";