acegames Posted July 22, 2009 Share Posted July 22, 2009 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"]; } } Quote Link to comment https://forums.phpfreaks.com/topic/167016-help-please-with-results-from-query/ Share on other sites More sharing options...
kickstart Posted July 22, 2009 Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167016-help-please-with-results-from-query/#findComment-880645 Share on other sites More sharing options...
acegames Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks , sorry I did not post the full code just what I was working on I now think the error is elsewhere as I have duplicate entries for friendid requesterid & requesterid friendid Quote Link to comment https://forums.phpfreaks.com/topic/167016-help-please-with-results-from-query/#findComment-880649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.