Jump to content

Recommended Posts

Is there a way to put my two whiles together, I was thinking it would be easier for pagination then.
[code=php:0]
<?
$friendcount1 = mysql_query("SELECT * FROM friends WHERE friendid = '$GET'");
$friends1 = mysql_num_rows($friendcount1);
$friendcount2 = mysql_query("SELECT * FROM friends WHERE friendid2 = '$GET'");
$friends2 = mysql_num_rows($friendcount2);
$friends = $friends1+$friends2;
//unrelated code here
echo "<br><br>";
while($friendslot1 = mysql_fetch_array($friendcount1)){
$friendmain = $friendslot1[friendid2];
$f1 = "SELECT * FROM users WHERE id = '$friendmain' LIMIT 1";
$f2 = mysql_query($f1);
$play = mysql_fetch_assoc($f2);
echo "<a href='viewprofile.php?id=$play[id]'><img src='$play[avatar]' border='0' height='85' width='85'><br>$play[firstn] $play[lastn]</a><br><br>";
}

while($friendslot2 = mysql_fetch_array($friendcount2)){
$friendmain2 = $friendslot2[friendid];
$f3 = "SELECT * FROM users WHERE id = '$friendmain2' LIMIT 1";
$f4 = mysql_query($f3);
$play2 = mysql_fetch_assoc($f4);
echo "<a href='viewprofile.php?id=$play2[id]'><img src='$play2[avatar]' border='0' height='85' width='85'><br>$play2[firstn] $play2[lastn]</a><br><br>";
}
?>
[/code]

Also is there any tutorials anyone knows of for pagination...apart from the phpfreaks ones. They make no sense to me  :-X
Link to comment
https://forums.phpfreaks.com/topic/32587-while-and-pagination/
Share on other sites

could it be done like:
[code=php:0]$friendslist = $friendcount1+$friendcount2;
while($friendidloop = mysql_fetch_array($friendslist)){
$friendmain = $friendidloop[id];
$f1 = "SELECT * FROM users WHERE id = '$friendmain' LIMIT 1";
$f2 = mysql_query($f1);
$play = mysql_fetch_assoc($f2);
echo "<a href='viewprofile.php?id=$play[id]'><img src='$play[avatar]' border='0' height='85' width='85'><br>$play[firstn] $play[lastn]</a><br><br>";

}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32587-while-and-pagination/#findComment-151675
Share on other sites

try[code]$sql = "SELECT users.id AS id, users.avatar AS avatar, users.firstn AS firstn, users.lastn AS lastn FROM friends LEFT JOIN  users on users.id=IF(friendid = '$GET',friendid2,friendid) WHERE friendid = '$GET' OR friendid2 = '$GET'"
$result = mysql_query($sql);
while ($play = mysql_fetch_assoc($result) echo "<a href='viewprofile.php?id=$play2[id]'><img src='$play2[avatar]' border='0' height='85' width='85'><br>$play2[firstn] $play2[lastn]</a><br><br>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/32587-while-and-pagination/#findComment-151727
Share on other sites

sorry
i just check query not the rest of code
working code [code]//$GET=1;//for testing
$sql = "SELECT users.id AS id, users.avatar AS avatar, users.firstn AS firstn, users.lastn AS lastn FROM friends LEFT JOIN  users on users.id=IF(friendid = '$GET',friendid2,friendid) WHERE friendid = '$GET' OR friendid2 = '$GET'";
$result = mysql_query($sql);
while ($play = mysql_fetch_assoc($result)) echo "<a href='viewprofile.php?id=$play[id]'><img src='$play[avatar]' border='0' height='85' width='85'><br>$play[firstn] $play[lastn]</a><br><br>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/32587-while-and-pagination/#findComment-152501
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.