shorty3 Posted April 16, 2010 Share Posted April 16, 2010 Right im trying to add friends to my website but i ran into a slight problem through my little knowledge of php i got this code <? $query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'"); $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<td height='20'><center>No friends</center></td></tr>"; } while($dip=mysql_fetch_object($query_friends)){ echo "<tr><td height='20'> <a href='profile.php?viewuser=$dip->person'>$dip->person</a> "; } ?> Right what i want is the friends to show up with there profile pictures just like on facebook but the users database holds the profile picture i thought this would work <? $image = mysql_query("SELECT * FROM users WHERE username = '$viewuser'"); $fq = mysql_fetch_object($image); $query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'"); $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<td height='20'><center>No friends</center></td></tr>"; } while($dip=mysql_fetch_object($query_friends)){ echo "<tr><td height='20'> <img src='$fq->image' width='70' height='70' border='1'><a href='profile.php?viewuser=$dip->person'>$dip->person</a> "; } ?> But With no luck can any one lead me on the right patch thank you Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/ Share on other sites More sharing options...
andrewgauger Posted April 16, 2010 Share Posted April 16, 2010 Believe it or not the code should work. The problem probably is that the images are stored in a different directory than the script is located. You are going to have to find out the directory the script executes in: echo $_SERVER["PHP_SELF"]; Then find a picture. You'll probably notice that they are not in the same directory. So if your echo results in: /scripts/display.php and your images are in: /images/mypic.jpg you will need to alter your source as: echo "<tr><td height='20'> <img src='../images/$fq->image' width='70' height='70' border='1'><a href='profile.php?viewuser=$dip->person'>$dip->person</a> "; Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042815 Share on other sites More sharing options...
shorty3 Posted April 16, 2010 Author Share Posted April 16, 2010 Thank you for your reply but i dont think you understand my problem Right i have two databases users and friends the users database as a row thts called image which hold the url of the image. The profile image is not from a folder its from a url in the database. Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042818 Share on other sites More sharing options...
andrewgauger Posted April 16, 2010 Share Posted April 16, 2010 Do you know the structure of the users table? If you use phpMyAdmin type in DESCRIBE users; That should give you the structure of the users table. It may be that instead of 'username' you need to match 'name' or something different. Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042822 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 So if your echo results in: /scripts/display.php and your images are in: /images/mypic.jpg Uh.. it should be ../../images/. <? $image = mysql_query("SELECT * FROM users WHERE username = '$viewuser'"); $fq = mysql_fetch_object($image); $query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'"); $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<td height='20'><center>No friends</center></td></tr>"; } while($dip=mysql_fetch_object($query_friends)){ echo "<tr><td height='20'> <img src='$fq->image' width='70' height='70' border='1'><a href='profile.php?viewuser=$dip->person'>$dip->person</a> "; } ?> But With no luck can any one lead me on the right patch thank you With no knowledge of what $fq->image outputs, it's hard to help. Can you please run - echo $fq->image; in your while loop and either verify the URL or post it here? Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042845 Share on other sites More sharing options...
shorty3 Posted April 16, 2010 Author Share Posted April 16, 2010 Right the users of the website upload the url of the image to the database so <img src='$fq->image' width='70' height='70' border='1'> so $fq->image is from the users database to make the url into the image Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042931 Share on other sites More sharing options...
shorty3 Posted April 16, 2010 Author Share Posted April 16, 2010 Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1042946 Share on other sites More sharing options...
shorty3 Posted April 16, 2010 Author Share Posted April 16, 2010 No one gunna help hmm Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1043012 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 I use something similar to this. Please tell me the following result. echo $fq->image; Link to comment https://forums.phpfreaks.com/topic/198709-how-can-i-also-get-the-profile-picture-working-aswell/#findComment-1043020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.