Apologies in advance for the "programming for dummies" question... I searched in vain for a previous discussion about this.
So I've got a MySQL table full of powerboats. Each row has basic powerboat info (make/model/etc.) plus scores from 1-10 for a few different traits -- "power", "comfort", and "style". I want to help users find the powerboat that meets their individual needs.
By default, the data is ordered by "totalscore" from high to low, like so:
$sql = "SELECT *,(power + comfort + style) as totalscore FROM boats ORDER BY totalscore DESC";
... and I loop through the results with PHP and display them as a list.
But then I give the user a series of Yes/No questions to determine individual preferences, and I want each answer to change the value of totalscore in the user's session -- and thus change the order of the list items.
In other words, I want $_SESSION["totalscore"]
to change with each Yes/No user input...and the user's results should then be ordered from high to low by $_SESSION["totalscore"]
, not the original totalscore from the database.
Schematic Example
- Boston Whaler 370. power=7, comfort=8, style=6, totalscore=21
- Boston Whaler 350. power=5, comfort=7, style=8, totalscore=20
Question 1: Do you love style? Yes/No
if Yes {
$_SESSION["totalscore"] = totalscore + style;
reorder list items by $_SESSION["totalscore"]; // the 350 is now #1
}
if No {
$_SESSION["totalscore"] = totalscore + (style/2);
reorder list items by $_SESSION["totalscore"]; // they're now tied for #1
}
Etc.
What's tripping me up conceptually is that $_SESSION["totalscore"]
would be stored as a cookie, whereas the original totalscore comes from the database query. So once I switch from totalscore to $_SESSION["totalscore"]
, I'm at a loss as to how to reorder the list items.
Can someone point me in the right direction, if only in a schematic way? I want to figure it out, but I'm not sure WHAT to figure out at this point. Thanks very much.