faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 7 people (43%) answered Yes
Recently 2 of 6 people (33%) answered Yes

Entry

How do I store a count on a thumbs up and thumbs down rating for a site?

Sep 4th, 2000 19:20
Craig Fratrik, Terry Morris,


1) Create a table with a create statement similiar to the one below i 
assume that you have selected your database and in the php connected:
<MYSQL>
     CREATE TABLE ratings (thmbup int, thmbdn int);
2) Insert a table entry like:
<MYSQL>
     INSERT INTO ratings (thmbup, thmbdn) VALUES (0,0);
3) Query the data like:
<PHP>
     $q = "SELECT * FROM ratings;";
     $results = mysql_query($q) or die("BAD QUERY: $q);
     $result = mysql_fetch_array($results);
     $thumbsup = $result['thmbup'];
     $thumbsdown = $resutl['thmbdn'];
4) To change the data you first must delet the old data after querying 
it from #3:
<PHP>
     $q = "DELETE FROM ratings;";
     mysql_query($q) or die("BAD QUERY: $q");
     $q = "INSERT INTO ratings (thmbup, thmbdn) VALUES ($newthumbsup, ";
     $q .= "$newthumbsdown);";
     mysql_query($q) or die("BAD QUERY: $q");