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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:24:22+00:00 2026-06-17T17:24:22+00:00

So I have 3 tables: users, posts, private. In this example, lizzy created a

  • 0

So I have 3 tables: users, posts, private. In this example, lizzy created a private post ‘Dating’ and only wants her girlfriends to see it ‘authorized_user_ids’ in the private table, and herself ‘user_id’ in posts table.

users
user_id   user_name
   1        tony
   2        steph
   3        lizzy
   4        adam
   5        lara
   6        alexa


posts
post_id   user_id   post_name   private (0 is public, 1 is private to authorized users)
   1         1       Coding        0
   2         3       Dating        1
   3         3       Show Me       0

private
private_id   post_id   authorized_user_ids
    1           2             2,5,6

Only the private poster user_id and the authorized_user_ids should see the ‘Dating’ post by lizzy, but everyone should be able to see the ‘Show Me’ post by lizzy. Logged out users and users not authorized should not see anything. Is that the most efficient way to go about it, or should it be:

private
private_id   post_id   authorized_user_id
    1           2               2
    2           2               5
    3           2               6

That’s my first question. My second is what would be the best way to tackle it in php (display to authorized_user_ids) when pulling the data from a mysql db? Do we do a second query based on the ‘private’ flag in the posts table? If it is 1, we query in the while loop to get the ‘authorized_user_ids’ from the private table, and if it matches the $logged_in_id of the logged in user, then we display ‘Dating’? Or should there be a join somewhere in the main query with the ‘authorized _user_ids’ using the ‘post_id’ in the private table and the posts table? Any help on how to most efficiently do this is appreciated.

  • 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-17T17:24:23+00:00Added an answer on June 17, 2026 at 5:24 pm

    First Q: I would definitely go with the second version. Storing authorized_user_id as a CSV will cause both DB read and write operations to become much less efficient as you will end up splitting the CSV values all the time in your application code and generating bad dynamic SQL statements in order to process updates. You should never have to write PHP code to help with finding the intersection of different sets of data like that, use SQL.

    Second Q: Use joins, no while loops for example

    SELECT DISTINCT p.post_id, p.post_name FROM users as u
    JOIN posts as p on p.user_id=u.user_id 
    LEFT JOIN private pv on pv.post_id=p.post_id
    WHERE (p.private=0) OR  (authorized_user_id={$logged_in_id} and p.private=1)
    

    The above (or very similar) will list all posts $logged_in_id is 2 but only public ones when $logged_in_id is 4 etc.

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

Sidebar

Related Questions

So I have 4 tables: users, posts, private, threads. In this example, lizzy created
In my application I have the following tables: Posts id title content Users id
I have two tables: posts - holds post information listen - holds information on
I have Two diff tables as given below: users and posts Need data from
I have 2 tables, one called posts and one called users . Inside posts
I have two tables: users and posts . I'm trying to select any users
I have a Database with the following two tables, USERS, POSTS I am looking
I have a MySQL database with 3 tables: users, posts, and users_posts. The users-posts
I have is a users table, a posts table, a private table, and a
I have these tables: USERS: user_ID username password email data_registered POSTS: post_ID user_ID post_title

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.