Jump to content

How can i also get the profile picture working aswell


shorty3

Recommended Posts

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

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> ";

 

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.

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. 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.