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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:50:33+00:00 2026-05-12T20:50:33+00:00

SOLVED – see Bish below I’ve got a list of checkboxes that all dump

  • 0

SOLVED – see Bish below

I’ve got a list of checkboxes that all dump to $fruitid[], and a many-to-many table1:

BoxID  FruitID
 01      01
 01      02
 02      01
 02      03
 02      04
 03      02
 etc.     etc.

I want a user to check the box next to each fruit they want, and then query to pull up a list of each box that contains all of the fruit selected (and other fruit is ok, it’s a minimum requirement not an exact contents search).

My PHP is working nicely, but I’m puzzled by what I thought would be an easy MySQL string. Basically if I

SELECT boxid FROM table1 WHERE fruitid=$fruitid1 AND fruitid=$fruitid2 AND etc. 

until all the checked data is entered I end up with no results because no SINGLE row contains more than one fruitid. Is this making sense?

The only solution I can think of is a bunch of nested select statements, each one narrowing the results pool from the previous subset until you’ve search for all the values in the original array. This seems both CPU intensive and cumbersome to code.

Is there a better way?

  • 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-12T20:50:33+00:00Added an answer on May 12, 2026 at 8:50 pm

    Building on the current suggestions, you should be able to get what you’re looking for by simply adding GROUP BY and HAVING clauses:

    SELECT boxid FROM table1 WHERE fruitid IN ($fruitid1, $fruitid2, ...) GROUP BY boxid HAVING COUNT(*) = $selectedFruitCount;
    

    By grouping by boxid and adding the COUNT(), you get the number of ‘interesting’ fruits that each box contains. If that count equals the total number of fruits that were selected, then that box must contain each of the selected fruits (and possibly more). Keep in mind that this assumes that the combination of boxid and fruitid is unique.

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

Sidebar

Related Questions

SOLVED: See my answer below I'm experiencing the same issue that Austin Hyde experienced
SOLVED: See my solution below! using aspx with C# code behind. I have the
SOLVED See my answer below. Question left unchanged for anyone else who has trouble
[SOLVED]: Applying proper list iteration procedure fixed problem. (Shown below) I currently have a
Solved! See update below. We are porting a large C++ application to Android, and
[SOLVED: See solution below.] I'm having a problem writing a RewriteMap program (using Python).
[SOLVED (see answer below)] I am using SpreadsheetWorker API to make working with Open
Solved: see answer below I am sub-classing Dialog to create a dialog with a
Solved: See comments below. I've created a Tabs inside of a Dialog box, but
SOLVED BELOW See below for solution I have a ListView with a custom adapter

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.