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
https://forums.phpfreaks.com/topic/167016-help-please-with-results-from-query/
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

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.