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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:40:54+00:00 2026-06-08T07:40:54+00:00

I’m attempting to build a PHP based web software and I came across a

  • 0

I’m attempting to build a PHP based web software and I came across a problem that I do not know the solution’s syntax for.

Basically, I have two tables:

+-------------+     +---------------+
| Certs       |     | Clients       |
+-------------+     +---------------+
| userID      |     | eID           |
| prodID      |     | prods         |
| prodName    |     +---------------+
+-------------+

Here, every product an individual buys is stored by his unique userID and the product’s unique prodID.

Clients are like sellers who has different Ids themselves and prods which is a string of comma deli-mitered product IDs.

Example rows in the certs table would be like:

userID  |  prodID  |  prodName
------------------------------
9000    |  42      |  Pen     
4234    |  54      |  Pencil
9000    |  54      |  Pencil

An example client row would be like:

eID  |  prods
-------------
595  |  42,54

Now, I need to form a query that returns back all userIDs that have purchased all products of a particular seller.

Eg, for seller ID 595 it should return 9000, as userID 9000 has bought both 42 and 54.

Table structure can be modified for convenience however I cannot create a normalized list of products tied to their seller due to other technicalities.

Any help would be much appreciated! Thanks~

Note: Another way to put it is to keep the list of prods of a seller in a result type array.
Then SELECT prodID FROM certs WHERE userID = x
And finally check if, the result array of prodID has all elements of array prods.

  • 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-08T07:40:56+00:00Added an answer on June 8, 2026 at 7:40 am

    Try this solution:

    SELECT a.userID
    FROM certs a
    INNER JOIN clients b ON b.eID = 595 AND FIND_IN_SET(a.prodID, b.prods) > 0
    CROSS JOIN
    (
        SELECT (LENGTH(prods) - LENGTH(REPLACE(prods, ',', ''))) + 1 AS prodcnt
        FROM clients
        WHERE eID = 595
    ) c
    GROUP BY a.userID, c.prodcnt
    HAVING COUNT(1) = c.prodcnt
    

    How it works:

    CROSS JOIN
    (
        SELECT (LENGTH(prods) - LENGTH(REPLACE(prods, ',', ''))) + 1 AS prodcnt
        FROM clients
        WHERE eID = 595
    ) c
    

    What this does is append onto each row the count of the number of prodIDs that a particular seller has. We calculate it by taking the string length of the CSV list and substracting the length of the same CSV list but without commas, and add one to the difference. Example:

    String length of “54,234,436” is 10.

    Replace the commas:

    String length of “54234436” is 8.

    So then (10-8)+1 = 3.

    Three items in the list.


    We use FIND_IN_SET as a join condition between certs and clients to determine whether or not the prodID exists within the CSV prods list.

    FIND_IN_SET basically returns the 1-based index position of a particular item in a CSV list. For example:

    FIND_IN_SET('54', '34,76,54,128') 
    

    will return 3 because 54 exists as the third item in the list. We only need to check if it exists within the list for the join condition, so we just check if it’s > 0. If the item is not in the CSV list, it will return 0.


    Once we have the cartesian-joined count of products of a particular client, and the tables joined, the intermediate result-set would look something like this:

    a.userID  |  a.prodID  |  b.eID  |  b.prods  |  c.prodcnt
    ---------------------------------------------------------
    9000      |  42        |  595    |  42,54    |  2
    4234      |  54        |  595    |  42,54    |  2
    9000      |  54        |  595    |  42,54    |  2
    

    Each of these rows satisfied the join condition.

    We then group by the userID to count the number of rows per userID. Since 9000 has the same number of rows as the repeating value in c.prodcnt, that row is returned. userID 4234 is fitlered out because only one row satisfied the join condition.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,

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.