Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3345280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:10:03+00:00 2026-05-18T01:10:03+00:00

I wish so the users can only send to their friends. Right now I

  • 0

I wish so the users can only send to their friends.
Right now I have this:

$qur = mysql_query("
 SELECT users.id, users.firstname, users.lastname, 
 (users.firstname = '$firstname' AND users.lastname = '$lastname') AS full FROM users 
WHERE
(users.firstname = '$firstname' AND users.lastname='$lastname') 
 OR (users.firstname LIKE '$firstname%' AND users.lastname LIKE '$lastname%')
 OR users.firstname LIKE '$firstname%' OR users.lastname LIKE '$firstname%'
 ORDER BY (users.firstname = '$firstname' AND users.lastname='$lastname') DESC") or die(mysql_error());

This shows everyone in users that are like $firstname , $lastname

Now I have tried to make only select the user´s friends $firstname , $lastname, by adding this:

  INNER JOIN users_friends ON users.id=users_friends.uID
WHERE users_friends.bID='$USER' AND users_friends.type = '$typeUsers' AND

So it got like this:

$qur = mysql_query("
 SELECT users.id, users.firstname, users.lastname, 
 (users.firstname = '$firstname' AND users.lastname = '$lastname') AS full FROM users 
  INNER JOIN users_friends ON users.id=users_friends.uID
WHERE users_friends.bID='$USER' AND users_friends.type = '$typeUsers' AND
(users.firstname = '$firstname' AND users.lastname='$lastname') 
 OR (users.firstname LIKE '$firstname%' AND users.lastname LIKE '$lastname%')
 OR users.firstname LIKE '$firstname%' OR users.lastname LIKE '$firstname%'
 ORDER BY (users.firstname = '$firstname' AND users.lastname='$lastname') DESC") or die(mysql_error());

If there exists total 4 with lastname “fox”, and I am only friends with 1 of them with firstname “megan”, it spits out this:

Megan Fox
Megan Fox
Mami Fox
Mimi Fox
Mumu Fox

As you can see here, it spits out “Megan Fox(who i am friends with)” twice. And i think that’s because somewhere in the SQL it spits out everyone, AND THEN it spits out the friend. But how can i not spit out everyone, but only my friend?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:10:03+00:00Added an answer on May 18, 2026 at 1:10 am

    It’s because the operator precedence. The expression x and y or z does’t evaluate as x and (y or z) but as (x and y) or z. therefore, the friend limitation only applies to the first way of matching the names.

    You need some parentheses around the name conditions:

    WHERE users_friends.bID='$USER' AND users_friends.type = '$typeUsers' AND (
     (users.firstname = '$firstname' AND users.lastname='$lastname') OR
     (users.firstname LIKE '$firstname%' AND users.lastname LIKE '$lastname%') OR
     users.firstname LIKE '$firstname%' OR
     users.lastname LIKE '$firstname%'
    )
    

    As part of the condition for joining in the friends table is only applied for some of the records, you will be joining in records from other users also. The reason that Megan Fox appears twice is most likely because she is friend with someone else also, so she appears twice in the friends table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a input field where i only wish users to type numbers html:
I have a table users. I wish to update the column email based on
I have a web form where users answer questions via dropdowns, and I wish
I have a WPF application. My users wish to see what stored procedures/functions an
I wish to show users of my website a pop-up alert on their first
I wish to give my users only vertical scroll and that too up to
I want to use Calendar widget to help users select date. I wish use
I've built a Silverlight website where users can create an account and login. Right
I have a input field where users can write a domain name that they
Afternoon All, I have a web form that i wish my user to fill

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.