helpchrisplz
asked on
voting/ rating systom
am trying to make a rating system for top products on my site. i would like my users to click a button to like a product and then on the home page it will only show the top 5 liked products.
the voting system will take all votes from all users of the site and then display the top 5 on the home page for every on to see. i dont want it to be like target advertising but just to show what every one is liking across the hole site.
so am trying to think of some php to get this working.
query to get the current number of likes for the product then update the current number of likes by 1.
a way of not allowing users to vote more than once on a product
any help would be great thx.
the voting system will take all votes from all users of the site and then display the top 5 on the home page for every on to see. i dont want it to be like target advertising but just to show what every one is liking across the hole site.
so am trying to think of some php to get this working.
query to get the current number of likes for the product then update the current number of likes by 1.
a way of not allowing users to vote more than once on a product
any help would be great thx.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why use a vote table instead of a vote counter? Because it will allow you to do geographical and time-sensitive analysis, sort of like "trending topics" on Twitter. Older votes can go into a summary table where only the counts matter.
a way of not allowing users to vote more than once on a product
That would usually be done with a persistent browser cookie, however you need to be aware that clients can and do lose their cookies, sometimes deliberately. You might also record their IP address, but this is problematic because clients can and do vote from different machines. And some servers aggregate the IP address for (for example) everyone in an office. And AOL, plus a few other ISP companies may provide unpredictable IP addresses.
If you go the cookie route, you would set the cookie at the time you received the vote. PHP has the setcookie() function to help you do this.
HTH, and please post back with any specific questions, ~Ray
a way of not allowing users to vote more than once on a product
That would usually be done with a persistent browser cookie, however you need to be aware that clients can and do lose their cookies, sometimes deliberately. You might also record their IP address, but this is problematic because clients can and do vote from different machines. And some servers aggregate the IP address for (for example) everyone in an office. And AOL, plus a few other ISP companies may provide unpredictable IP addresses.
If you go the cookie route, you would set the cookie at the time you received the vote. PHP has the setcookie() function to help you do this.
HTH, and please post back with any specific questions, ~Ray
ASKER
please can you tell me what is wrong with my update query here:
$sql = "UPDATE members SET (UserName, Password, UserEmail, age, Location, Gender, Language) = ('$UserName', '$Password', '$UserEmail', '$Age', '$Location', '$Gender', '$Language') WHERE 'MemberID' = $MemberID";
$sql = "UPDATE members SET (UserName, Password, UserEmail, age, Location, Gender, Language) = ('$UserName', '$Password', '$UserEmail', '$Age', '$Location', '$Gender', '$Language') WHERE 'MemberID' = $MemberID";
ASKER
sorry that is another problem i have
I think it needs to be:
$sql = "UPDATE members SET UserName = '$UserName', Password = '$Password', etc...
$sql = "UPDATE members SET UserName = '$UserName', Password = '$Password', etc...
In addition to getting the query syntax right, you might want to avoid the use of MySQL reserved words for column names. That is one way you can be sure that catastrophe is not left to chance!
ASKER
this is great thx i have been AFK for a bit and only getting this sorted now but thx for this help
Thanks for the points. If you decide to use a pair of queries as described at ID:35068902 (SELECT + UPDATE) you will want to learn about LOCK TABLES. A better way might be to do the UPDATE first, then do the SELECT to get the results after the vote. Otherwise script racing may cause a loss of data.
Open in new window