Jump to content

Recommended Posts

I am wanting to do something similar to this:

http://www.dimarzio.com/pickup-picker

 

My question involves the concept rather than any specific code on how to execute this.

 

For example, we are selling violins and we want the user to input info about their playing style, and give them the three best violins based on their entry. This is the data I've been given:

 

Level:

Beginner

Intermediate

Advanced

[/td]

Soil, Kreisler, Gibson

Soil, Kreisler, Ysaye, Cremonese, Gibson

Cannon, Soil, Ysaye, K.Joseph, Keifetz

Bowing Style:

Soft

Medium

Hard

Soil, Medici, Kreisler

Soil, Medici, K.Joseph, Ysaye

Cannon, Kreisler, Soil, Heifetz

Musical Style

Classical

Fiddle

Rock

Ysaye, Soil, Provigny

Medici, Ysaye, K.Joseph

Kreisler, Diable, Vieuxtemps

Desired Tone:

Bright

Balanced

Dark

[td]Soil, Medici, Provigny

Kreisler, Soil, Ysaye

Cannon, Diable, Plowden

 

So if the user inputs Expert, Hard, Rock, and Dark I will data sets of violins consisting of: Cannon, Soil, Ysaye, K.Joseph, Heifetz // Cannon, Kreisler, Soil, Heifetz // Kreisler, Diable, Vieuxtemps // Cannon, Diable, Plowden

 

Out of those I need to output the user the three best choices for them. Cannon is listed in 3 out of the 4, so that has to be #1. Now there are three more violins that match two of the criteria. The Soil, Kriesler and Diable. In order to drill that down to two choices, I would think the questions would have to be ranked according to importance. For instance Tone is most important, followed by bowing style, musical genre, and skill level. Based on that ranking, the program should choose the Diable and Kreisler.

 

I am not entirely sure how to approach this. Since this data will not change frequently, should this even get the database involved? Should the info just be stored in a multi-dimensional array? Once the data is in an array, whether from the DB or not, how should I go about programming the logic to examine the arrays in order of importance and grab the violins that are most relevant?

 

Any help is much appreciated! I figured this was going to be easy, until I actually started thinking about it!

Link to comment
https://forums.phpfreaks.com/topic/262532-interactive-product-selector/
Share on other sites

Use a database. Even if you don't think you need one now, you do.

 

What you start off with are just four separate criteria. You could construct a single query that would give you the results you want, but that's a hassle. So start easy.

 

Go through the criteria and find the instruments that match each one. Level=Advanced finds five so give them each a point and hold onto them. With Bowing Style=Hard you get four, all of which you've found previously - give them another point. For Musical Style=Rock there's one familiar one and two new ones - give them points too. Finally there's Desired Tone=Dark and two more familiar instruments (and one new one). More points.

You can easily weight each category too by giving more or less points. You could start with a baseline of 10 points and say that "very important" = 15 while "not important" = 5. With a bit more math you can rank matching as a percentage.

 

Once you've gotten that working you can have a go at a single unified query. It's actually not that hard if you were to, say, use a few UNIONs.

# level=advanced is of normal importance
SELECT 10, instrument FROM instrument_table WHERE level = advanced

# bowing style is of normal importance
UNION ALL
SELECT 10, instrument FROM instrument_table WHERE bowing_style = hard

# musical style is very important
UNION ALL
SELECT 15, instrument FROM instrument_table WHERE musical_style = rock

# desired tone is also very important
UNION ALL
SELECT 15, instrument FROM instrument_table WHERE desired_tone = dark

Throw that in a subquery then SUM() + GROUP BY the results and you've got a bare minimum.

Awesome! The point system is perfect! Thank you SO much for that bit of advice. One last question. When you say, "give them each a point and hold onto them" are you assigning these points all within the db query with SELECT 10 or SELECT 15, or would you add the points up in a php array?

 

I've never performed that type of weighted db query before, so I will have to do some research, but if I understand you correctly, I'll be able to perform the query and simply take the top three items in the outputted array. Correct?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.