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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:58:46+00:00 2026-05-25T11:58:46+00:00

I’m trying to calculate how closely an item matches a user’s defined preferences. The

  • 0

I’m trying to calculate how closely an item matches a user’s defined preferences. The following is how I thought of doing it. But I’m not overly experienced and wanted to know if there might be a better way to go about it.

Using cars as a simple example. We will narrow it down to color and style of car (car, van, etc.).


Part One

The user selects in an HTML form the following:

Color: ( )White, (*)Black, ( )Red
Style: ( )Car, ( )Van, (*)Suv, (*)Truck

Now if I convert the above into a binary number where the first digit = first attribute (white) and continues on.

Attribute Code = 0100011 (black, suv, truck)


Part Two

Now with MySQL

Select item_id, attribute_code FROM items

items table = [item_id][attribute_code]

Next use PHP to calculate how closely each items attribute code matches the users preferences.

// Set users attribute code to var
$user_pref = $_POST['user_att_code'];

while($row=mysql_fetch_array($result))
{
    // Pull attribute_code from database and put into var
    $item_code = $row['attribute_code'];

    // Set counters
    $count_digit = 0;
    $count_match = 0;

    // Length of attribute code
    $length = 7;

    // Start calculating match
    while($count_digit <= $length)
    {
        // Does first digit of users code = 1?
        // Does first digit of items code = 1?
        if($user_pref{$count_digit} != 0 && $user_pref{$count_digit} == $item_code{$count_digit})
        {
            // Add a positive match point to counter
            $count_match++;
        }

        // Next digit in code
        $count_digit++;
    }

    if($count_match > 0)
    {
    // Make array of item_id and match amount
    $item_search [$row['item_id']] = $count_match;
    }   
}

// Sort array by most similar
arsort($item_search);

Then a little more code is used to calculate a percentage.

The above did the following: It took the users desired attribute code and compared it to every items attribute code in the database. It went digit by digit through each code and made a tally every time there was a match. At the end it put the tally for that item into an array and went onto the next item’s attribute code.

user: 0100011
it_1: 0100011 = 100% match
it_2: 0100100 = 50% match
it_3: 0011000 = 0% match
// If you notice the 50% does not make sense ignore it.
// I left something out for simplification.

Now I know this works. However, it does not seem like a good way to go about it. Performance wise mostly. Assuming over 150,000 items, and an attribute code length of about 200. That’s at least 30,000,000 calculations for one search (based on above).

Is there another way perhaps? Is this a big deal?

  • 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-25T11:58:47+00:00Added an answer on May 25, 2026 at 11:58 am

    To achieve better perfomance you should reorganise your system.

    Use separated tables for Colors and Styles. Also tables to organize relations between data (Items – Colors, Items – Styles).

    You will be able to select from database ONLY parameters user has selected and not to iterate over all Items each request.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.