...

View Full Version : Your Friends - Script



IamHe
03-19-2009, 07:48 PM
I made this script, the idea was to showa user theyer friends.
it successfully echos your number of friends.
but the problem im having is , it only echos the first row.
so its only showing your first friend, going by id.

so it could say, you have six friends, yet only show you one.
i cant figure it out.
probally a stupid mistake.

any ideas?

thanks allot






<?
session_start();
include ('dbc.php');
include ('functions.php');
?>

<?php if (isset($_SESSION['user'])) { ?>
<?
$sql = 'SELECT * FROM `friends` WHERE `friend` = "'.$_SESSION['user'].'" ORDER BY id ASC LIMIT 15 ';
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);


if ($num > 0)
{
echo "You Currently have", $num," friends<br /><br /><br />";


}
else
{
echo "You Currently Have No Friends.";
}

?>

<?

$sql = 'SELECT * FROM `friends` WHERE `friend` = "'.$_SESSION['user'].'" ORDER BY id ASC LIMIT 15 ';
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$sql2 = 'SELECT * FROM `users` WHERE `username` = "'.$row['befriended'].'" ORDER BY id ASC LIMIT 15 ';
$result2 = mysql_query($sql2) or die (mysql_error());
$row2 = mysql_fetch_array($result2);


if ($num > 0)
{
echo "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
}

?>


<? } ?>

steelaz
03-19-2009, 07:56 PM
At the bottom of the script replace



$row2 = mysql_fetch_array($result2);


if ($num > 0)
{
echo "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
}


with



while ($row2 = mysql_fetch_array($result2))
{
echo "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
}


It will cycle through all results from your second query

IamHe
03-20-2009, 01:05 PM
At the bottom of the script replace



$row2 = mysql_fetch_array($result2);


if ($num > 0)
{
echo "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
}


with



while ($row2 = mysql_fetch_array($result2))
{
echo "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
}


It will cycle through all results from your second query


steelaz , thanks allot !!:) i really apreaciate your help,
at the minute im only really in the learning stages of php,

but i looked up the while condition on php . net , and i now understand what it dose//means , so thanks allot , i really apreaciate it!.

i do have another question though.

the way ive done it now.

is so it echos , the info in coloms, the problem is, when the page runs out, it carrys on going and dosent drop to a new line , is there any way of doing like
after its shown 4, break to a new line/?


thanks allot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum