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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In general, I'll say "yes". Having specified default and fill… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer You can save the variable in a session. In your… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer This is expected behavior. The CLR property is merely a… May 11, 2026 at 4:41 pm

Related Questions

Hi I need to pass some objects to and from .Net and a Flex
I am testing against the following test document: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC
Hi I'm trying to get some practice with Linked Lists. I Defined an Object
Given a table of models 'A', that can have multiple child models 'B', of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.