|
Posted by NC on 05/05/06 20:22
maxvalery@gmail.com wrote:
>
> Basically, a user makes some radio-button choces, and the script
> matches the choices to some database records filled with vehicle
> information. Because I want to have more than 2 questions, I can't
> even begin imagining the difficulty of hard-coding all possible choices
> - behold the power of a factorial :)
>
> What would be the logic/algorithm for something like that? What
> would be the database structure?
The logic is that of scoring and weighing.
First, you assign attribute scores to each vehicle (let's say, you have
three scores: reliability, fuel economy, and price, all on a scale from
1 to 10, with 1 being "extremely poor" and 10 being "excellent"). So
you have a table in a database with fields like this:
id (int)
make (varchar)
model (varchar)
year (int)
reliability (int)
economy (int)
price (int)
Then, you use user responses to elicit which score is most important to
a particular user (each question can add points to relative importance
of one or more scores). How you weigh the results is entirely up to
you. You can use raw points or simply give a weight of 3 to the most
important score, 2 to the next in order of importance, and 1 to the
least important.
Let's say you decided to store reliability, economy, and price weights
in three variables, $w_reliability, $w_economy, and $w_price. Now you
can form your query, execute it, and display results:
$year = '2007';
$query = <<<EOQ
SELECT make, model,
($w_reliability * reliability +
$w_economy * economy +
$w_price * price) AS composite_score
FROM vehicles
WHERE year = $year
ORDER BY composite_score DESC
LIMIT 5
EOQ;
$result = mysql_query($query);
echo "Your responses indicate that you might be interested in: \r\n";
while ($record = mysql_fetch_array($result)) {
echo $record['make'], ' ', $record['model'], "\r\n";
}
Cheers,
NC
Navigation:
[Reply to this message]
|