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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:14:31+00:00 2026-06-12T13:14:31+00:00

I need to do a PDO statement that cross-references 3 tables and it seems

  • 0

I need to do a PDO statement that cross-references 3 tables and it seems i’m stuck.

It basically needs 4 records from 2 tables (myl_contacts and mya_users) and they don’t need to be listed in myl_blocked_contacts.

In myl_blocked_contacts are the rows with id, and contact_type (‘a’, ‘l’, ‘x’, etc) which are blocked, and I need to select from myl_contacts users that I have and are NOT blocked (hence are not in myl_blocked contacts).

Here’s the piece of PDO::mysql query that I’ve done so far. I don’t know where to go from here, I am trying a lot of things off the net, but I seem to go in the wrong direction somehow. Thanks!

$query = "SELECT myl_contacts.contact_id, mya_users.name, mya_users.city, mya_users.ext 
      from myl_contacts, mya_users, 
          LEFT JOIN myl_blocked_contacts 
      WHERE myl_contacts.contact_type='a' 
        AND myl_contacts.label_id=:id 
        AND (myl_blocked_contacts.contact_type!='a' 
         AND myl_blocked_contacts.contact_id!=mya_users.id)
     ";
                                            $result = $db->prepare($query);
                                            $result->bindValue(':id', $_id, PDO::PARAM_INT);
                                            $result->execute();
  • 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-06-12T13:14:32+00:00Added an answer on June 12, 2026 at 1:14 pm

    I’m not sure if I get your problem right.
    I don’t understand why you use the LEFT JOIN.
    Isn’t there a ON part needed? (like ... t1 LEFT JOIN t2 ON t1.ID = t2.t1ID ...)

    What if you just write:

    SELECT 
        myl_contacts.contact_id, 
        mya_users.name, 
        mya_users.city, 
        mya_users.ext 
    FROM 
        myl_contacts, 
        mya_users, 
    WHERE 
        myl_contacts.contact_type='a' 
        AND myl_contacts.label_id=:id 
        AND mya_users.id NOT IN
            SELECT 
                contact_id
            FROM
                myl_blocked_contacts
    

    I also don’t quite understand why you SELECT rows from different tables which are not related. This might make sense, but does not necessarily. If there’s some connection between these tables, you might want to add an INNER JOIN…

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

Sidebar

Related Questions

I am trying to use a prepared statement that deletes from two (temporary) tables:
Need help with a query that I wrote: I have three tables Company id
I have a PDO statement as follows( AFAIK , PDO doesn't need data to
I need an insert statement that will do roughly this: INSERT INTO tblContent(postTitle, postBody,
I need the following authentication script finished. I am weak at php/pdo so I
Can someone confirm this: If I am using PDO::PARAM, I don't need to Filter
New to PDO - do I need to escape arguments I'm passing into a
How would I convert a PDOStatement to JSON? I need to jsonify a PDO::FETCH_OBJ
I have found many ways to use the exec statement for PDO, but I'm
I have a MySQL query that needs to change depending on what parameters are

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.