Jump to content

Help Please With Results From Query


acegames

Recommended Posts

I am trying to select from a friends table where either the requester id or friend id is the userid ($id) and approved is 1

 

I get the results but I cant manage to get it to show the correct username for all results , if the requester id is the $id I want it to show the friendid and if the friendid is the $id I want it to show the requester id

 

$psql = mysql_query("SELECT * FROM `friends` WHERE (requesterid='".$id."' OR friendid='".$id."') AND  `approved`='1'  LIMIT $startt , 20;", $conn);	





if($num1>0) {


    while($buds=mysql_fetch_array($psql))
    {
$r = $buds["requesterid"];
      if($r[requesterid]==$id)

      {
$r = $buds["friendid"];
     if($r[friendid]==$id)

      {
$r = $buds["requesterid"];
  
      }
}

Link to comment
Share on other sites

Hi

 

Few errors I can see. Few missing quotes, $num1 doesn't appear to have been set, few missing closing curly brackets and a missing $ sign when assigning $psql.

 

<?php

$psql = mysql_query("SELECT * FROM `friends` WHERE (requesterid='".$id."' OR friendid='".$id."') AND  `approved`='1'  LIMIT $startt , 20;", $conn);

 

if($num1>0)

{

while($buds=mysql_fetch_array($psql))

{

$r = $buds["requesterid"];

if($r['requesterid']==$id)

{

$r = $buds["friendid"];

}

else

{

if($r['friendid']==$id)

{

$r = $buds["requesterid"];

}

}

}

}

?>

 

All the best

 

Keith

Link to comment
Share on other sites

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.