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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:11:47+00:00 2026-05-20T10:11:47+00:00

Hey all. I think I have a logic error in my qry. The output

  • 0

Hey all. I think I have a logic error in my qry. The output is correct but in triplets. I’ve been staring at this for a long time and not seeing it. Can someone shed some light on this? Thanks!!

Also wanted to add this info as well.

  • $userid = 1
  • $UserIDAList = (1,1,6)
  • $UserIDBList = (2,3,1)

PHP-Code:

$result  = mysql_query("SELECT TBL_ContactsList.ContactID, TBL_ContactName.FirstName FROM TBL_ContactsList, TBL_ContactName WHERE ((TBL_ContactName.NameID != $userid) AND (TBL_ContactsList.ContactID != $userid)) AND ((TBL_ContactName.NameID IN ($UserIDAList) OR TBL_ContactName.NameID IN $UserIDBList)))");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf ("ID: %s  Name: %s", $row[0], $row[1]);
    echo "<br/>";
}

Only the SQL-Query (readability):

SELECT TBL_ContactsList.ContactID, TBL_ContactName.FirstName 
FROM TBL_ContactsList, TBL_ContactName 
WHERE ((TBL_ContactName.NameID != $userid) AND (TBL_ContactsList.ContactID != $userid)) 
AND ((TBL_ContactName.NameID IN ($UserIDAList) OR TBL_ContactName.NameID IN $UserIDBList)))

Output:

ID: 2 Name: Joe
ID: 3 Name: Joe
ID: 4 Name: Joe
ID: 2 Name: Jimbo
ID: 3 Name: Jimbo
ID: 4 Name: Jimbo
ID: 2 Name: Mike
ID: 3 Name: Mike

EDIT: Here is what I ended up using. (can’t figure out indent on here.)

But now I am missing an entry from the db.

$result = mysql_query("
SELECT cl.ContactID, cn.FirstName
FROM TBL_ContactName AS cn
INNER JOIN TBL_ContactsList AS cl
ON cl.ContactID = cn.NameID
WHERE
cn.NameID != $userid
AND (
cn.NameID IN ($UserIDBList) OR cn.NameID IN ($UserIDAList)
)
");

The output looks like this.
ID: 2 Name: Joe
ID: 3 Name: Jimbo

But when I put LEFT JOIN I get this. Close but still missing ID.
ID: 2 Name: Joe
ID: 3 Name: Jimbo
ID: Name: Mike

Any ideas?? THanks!

  • 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-20T10:11:48+00:00Added an answer on May 20, 2026 at 10:11 am

    If I got your SQL structure correctly, changing SQL like this should probably fix it. At least it’s a proper usage.

    $result=mysql_query("SELECT cl.ContactID, cn.FirstName FROM TBL_ContactsList cl INNER JOIN TBL_ContactName cn ON cn.NameID=cl.ContactID WHERE cn.NameID != $userid AND (CN.NameID IN ($UserIDAList) OR CL.NameID IN ($UserIDBList))");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.