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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:49:34+00:00 2026-06-12T19:49:34+00:00

I have a table called activities that looks like this id | related_id |

  • 0

I have a table called activities that looks like this


id | related_id | related_table | …

And 3 arrays, each named after a table, containing ID’s:

$clubs[1,2,3]; $vendors[4,5,6]; $users[7,8,9];

How do I select the activities that belong to the corresponding clubs, vendors, and users in the arrays? I only know very simple SQL, but am sure there is a way to do this.

I am looking to do this in 1 select statement, if possible. Otherwise I know how to do “where in” to do it in 3.

ANSWER:

Here is how I accomplished getting all the activites in 1 select:

'SELECT * from activities where (related_table = \'clubs\' and related_id in ('.$clubs_string.')) or  (related_table = \'vendors\' and related_id in ('.$vendors_string.')) or (related_table = \'users\' and related_id in ('.$users_string.'));';

See Morgan Wilde’s answer about implode()-ing the arrays to strings.

  • 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-12T19:49:35+00:00Added an answer on June 12, 2026 at 7:49 pm

    Well if I’ve got your question right, the way to find all activities that relate to club id’s saved in an array should be…

    $clubs_string = implode(",", $clubs); // convert your array into a comma separated string
    

    Once you’ve got that sorted, send a query like

    SELECT `id` FROM `activities` WHERE `related_id` IN ({$clubs_string}) AND `related_table` = 'club_table_name'
    

    You can repeat the same logic for all other table types that you have.

    Here you can find some neat MySQL WHERE IN examples – http://www.tutorialspoint.com/mysql/mysql-in-clause.htm

    Hope that helps!

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

Sidebar

Related Questions

I have a table called 'MyTable' that looks like: ID | Item | Type
I have table called Direccion other called Cliente each one defined like this public
Have a table called user_products that contains a record for each product the user
I have table called Data_Details and the data looks like: DateTimeClosed Datesub TimeSub 6/20/2011
i have table called table1 and it looks like the below record type tran_ref_number
I have a table called Activities and for each activity I can have zero
i have table called as Support, which have a field named Name and contains
I have table called posts in my DB. Each post has field called social_network
I have a table called user_details this table has got morethan 100k user details
In my db I a have table called users. In that table I have

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.