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 105381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:25:49+00:00 2026-05-11T01:25:49+00:00

Hi I need some help with the following scenario in php. I have a

  • 0

Hi I need some help with the following scenario in php. I have a db with users every user has an ID, have_card and want_card. I know how to make a direct match (one user trades with another user). But if there is no direct match but there is a circular swap like:

User #1 has card A wants card B

User #2 has card B wants card C

User #3 has card C wants card A

In this scenario there is no direct match between two users. But if:

User #1 gives his card to User #3

User #3 gives his card to User #2

User #2 gives his card to User #1

Every ones happy.

All the info I have to start with is User #1 how do I find User #2 and User #3?

Thanks to everyone for your answers.

  • 1 1 Answer
  • 2 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. 2026-05-11T01:25:49+00:00Added an answer on May 11, 2026 at 1:25 am

    This is a challenging scenario. I had to build this for a book swapping application a while back and using a white board I was able to more easily visual and solve the problem.

    What I did was use the same table inside the query multiple times, just using a different name.

    In my scenario, the books that were needed were in a separate table from the books the users had. Hopefully you’ll be able to see the logic in this query:

    $query = 'SELECT          A.Owner_ID as Owner_1, C.Owner_ID as Owner_2, E.Owner_ID as Owner_3      FROM         E_User_Books_Have as A, E_User_Books_Have as C, E_User_Books_Have as E,         E_User_Books_Needed as B, E_User_Books_Needed as D,E_User_Books_Needed as F      WHERE          A.Book_ID=D.Book_ID AND         C.Book_ID=F.Book_ID AND         E.Book_ID=B.Book_ID AND          A.Owner_ID='$ME' AND B.Owner_ID='$ME' AND A.ID='$ID'AND          C.Owner_ID=D.Owner_ID AND           E.Owner_ID=F.Owner_ID AND         C.Owner_ID!='$ME' AND         E.Owner_ID!='$ME''; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with the following scenario. Imagine a end-user receives an email
I need some help writing a regex. I have the following strings, xxx.yyy.wwwwwaaa_IN_123 xxx.rrrttttt_IN_12355
I need some help with something... say I have the following form... <form name=
I need your help with the following scenario: I am reading some data from
Need some help solving the following issue. I have web-application in Java, with Spring
I need some help translating the following shell scripts calls to PHP curl -3
I have the following strange situation here I need some help with: I am
I need some help figuring out why the following scenario does not work. I'm
I need some help optimizing the following method. The queries have become too costly
I have been following this article on Frustum culling, and I need some help

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.