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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:42:22+00:00 2026-05-19T03:42:22+00:00

I’m having trouble figuring out the best way to store what information my users

  • 0

I’m having trouble figuring out the best way to store what information my users want to see. I apologize for not being able to find an easy way to explain my problem, but here goes (the fruits are for example’s sake):

Let’s say my users have an option to keep track of the following fruits in their fridge:

Apples, Oranges, Grapes, Pears

The database is already setup with a table called ‘fruits’, where Apples is id_fruit=1, Oranges is id_fruit=2, etc.

Like I said all users have the OPTION to keep track of these fruits, however… I currently can not figure out an easy way to store the users selection of WHICH fruits they want to track. If user 1 doesn’t like Apples, he can just go into his settings, uncheck Apples and no longer have Apples show up in his dashboard.

The only way I can think to store this information is to create a table that contains for fields user_id, apples, orange, grapes, pears. And then storing the user_id and Yes/No or 0/1 for the fruits.

This causes major grief if I ever want to add more fruits, or whatever.

What is the best way to store this information in MySQL, using PHP. And how would I retrieve that info.

User logs in, check the DB for which fruits he wants to see, and display only those fruits he has chosen.

Any help would be greatly 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-05-19T03:42:23+00:00Added an answer on May 19, 2026 at 3:42 am

    This is a classic has-and-belongs-to-many, or simply many-to-many, relationship.

    Table `users`
    =============
    id
    name
    ...
    
    Table `fruits`
    ==============
    id
    name
    ...
    
    Table `users_fruits`
    ====================
    id
    user_id
    fruit_id
    

    In users_fruits you store one row per user-fruit relationship: (user_id: 42, fruit_id: 3).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img
I know there's a lot of other questions out there that deal with this

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.