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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:30:13+00:00 2026-06-15T19:30:13+00:00

I will break this into two parts: I have a user with a list

  • 0

I will break this into two parts:

  1. I have a user with a list of product ‘features’ that he desires. The user is asked to rank these features from 1-10. I also have a table full of products. Each of these products has various features. Some products will have all features 1-10, but some will only have a few of them. I’d like to determine which product matches the user’s ranking the best, and provide an ordered result set to the user, with the best match first and the worst match last.

  2. The aforementioned query is actually just one part of what the user is doing. The user is also providing other search criteria (e.g. product category, price, etc) along with the feature ranking. So, I’d like the feature matching to only apply to products that pass through this set of filters. How would I combine these?

I have found some similar questions like this and this, but they aren’t close enough for me to figure out how to apply those solutions to my situation.

The tables involved look something like this:

products (id,product)

features (id, feature)

product_features (id, product_id, feature_id)

and the user will be submitting his search through an array like this (where the keys are actually feature ids, and the rank is the value):

[users_features] => Array
    (
        [1] => Array
            (
                [rank] => 9
            )

        [2] => Array
            (
                [rank] => 1
            )

        [3] => Array
            (
                [rank] => 3
            )

(this will be a 10 item array right now, but could change in the future)

    )
  • 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-15T19:30:14+00:00Added an answer on June 15, 2026 at 7:30 pm

    I can’t quite get this to work using SQL only but a simple PHP solution would be similar to the following (untested):

    //Array of $productId => list of feature ids
    $products;
    $userFeatures;
    $scores = array();
    //For every product work out a score based on features and user ranking.
    foreach($products as $productId => $prodFeatures){
        $score = 0;
        foreach($prodFeatures as $feature){
            //Could also perhaps penalise products lacking features.
            $score += $userFeatures[$feature]["rank"];
        }
        $scores[$productId] = $score;
    }
    arsort($scores);
    echo "Best match is ".$scores[0];
    

    Obviously this is a bit rough and ready but hopefully it helps.

    Edit: This assumes that a ranking of 10 is the best.

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

Sidebar

Related Questions

I'm building a simulation in Java. So, I'll break my simulation into two parts:
...or will I break Eclipse integration? That's what happened when I did corresponding command
So I've decided to break up my CSS into an ie6-and-ie7-only file. I will
I have a table which has two keys and I cannot break the table
I have this problem to solve There is an input word from user which
MYSQL Database: I have a table of data that I need to put into
I have a file that users will purchase via paypal, clickbank and paydotcom. I
How can I break this string for licence plates v/s states? I have unique
Suppose I have two threads A and B that are both incrementing a ~global~
I have a process which I break into multiple processes and even when using

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.