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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:58:56+00:00 2026-05-17T02:58:56+00:00

On my website, I have a table movies and a table users I’m trying

  • 0

On my website, I have a table movies and a table users

I’m trying to have an “Add to favs” button that a user can click, which will add that movie to his favorites (ajax / javascript not necessary at the moment, just php).

So what’s the simplest way I could do something like that? I’ve thought about this but I can’t seem to find a solution (all I think of is way too complicated, and in my opinion not possible).

What’s your thoughts?

I don’t need a ready-made script, just an idea that could get me working (although if you have an example of such script, I’d be happy to look at it).

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-17T02:58:57+00:00Added an answer on May 17, 2026 at 2:58 am

    Add a third table:

    CREATE TABLE user_favorites (
      user_id INT NOT NULL,
      movie_id INT NOT NULL,
      PRIMARY KEY (user_id, movie_id),
      FOREIGN KEY user_id REFERENCES users (user_id),
      FOREIGN KEY movie_id REFERENCES movies (movie_id)
    )
    

    This is called an intersection table or join table, as it joins rows in the users table to rows in the movies table (as you see, each column is a foreign key). It is also defines a many-to-many relationship, because one user can like many movies and one movie can be liked by many users.

    When you go to add a favorite movie for a user, all you have to do is insert a row in this table with the ID of the user and the ID of the movie:

    INSERT INTO user_favorites(user_id, movie_id) VALUES([user ID], [movie ID])
    

    To see what movies a user has favorited:

    SELECT movie_id FROM user_favorites WHERE user_id = [user ID]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a social networking website. I have a table of Users. Each user
I have a table of user access sessions which records website visitor activity: accessid,
I have a website where users can rate comments that are left on pages.
I have a parent table called 'Website' which holds records about websites. I have
I have a website which contains a large (and wide) table. The table is
I have a dashboard in my website which contain some entries in table, each
I'm scraping a website that's mostly table based. I have <tr> tags that each
I have table called page which represents every single page in my website. page_id
I have a table that defines the possible categories in my website - fields
I have a table in a my Dynamic Data website that has a Primary

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.