Css
The first is the principle of implementation
The star rating I and II was implemented from the previous CSS, but it can be seen that by identifying the onclick and logging the data to the database and then invoking the data from the database for calculation
You can get the current score mean-the current score.
1. The following is the SQL that establishes the database
CREATE TABLE Ratings (
ID INT not NULL auto_increment PRIMARY KEY,
Total_votes INT not NULL,
Total_value INT not NULL,
which_id INT not NULL,
Which_table VARCHAR (255),
Used_ips Longtext NULL
); 2. parameter File Reference
<?php
Require ("connectdb.php");
Require ("closedb.php");
Require ("tablename.php");
Require ("opendb.php");
?>
3. Display of voting procedures and updating of voting data procedures
<?php
$rating _posted=$_get[' vote '];//pased variable by the "Stars value"
$id =$_get[' id '];
$query =mysql_query ("Select Total_votes, Total_value, used_ips from $tableName WHERE id= '". $id. "' ") or Die (" Error: ". Mysql_error ());
$numbers =mysql_fetch_assoc ($query);
$checkIP =unserialize ($numbers [' used_ips ']);
$count = $numbers [' total_votes '];//how many votes total
$current _rating= $numbers [' Total_value '];//total number of rating added together and stored
$sum = $rating _posted+ $current _rating;//Add together the current vote value and the total vote value
$tense = ($count ==1)? "Vote": "votes";//plural form Votes/vote
$voted = @mysql_fetch_assoc (@mysql_query ("Select title from $tableName WHERE used_ips like '%". $_server[' REMOTE_ADDR '). " % ' and id= ' $id ')); Pattern Match ip:suggested by bramus! http://www.bram.us/-This variable searches through the previous IP addresses that have voted and returns TRUE or False
if ($voted) {
echo "<div class=\" rating\ ">".
"<ul class=\" star-rating\ ">".
"<li class=\" current-rating\ "style=\" width: ". @number_format ($current _rating/$count, 2) *20. " Px;\ ">current rating.</li>".
"<li class=\" one-star\ ">1</li>".
"<li class=\" two-stars\ ">2</li>".
"<li class=\" three-stars\ ">3</li>".
"<li class=\" four-stars\ ">4</li>".
"<li class=\" five-stars\ ">5</li>".
"</ul>".
"<p>rating: <strong>". @number_format ($current _rating/$count, 2). " </strong> {". $count." ". $tense." Cast} <br/>you have previously voted.</p></div> ";//show the current value of the vote with T He numbers
}else{
if (Isset ($_get[' vote ')) {
if ($sum ==0) {
$added =0;//checking to the if the vote has been tallied
}else{
$added = $count +1;//increment The current number of votes
}
if (Is_array ($checkIP)) {
Array_push ($checkIP, $_server[' remote_addr ');//if it is a array i.e. already has entries the push in another value
}else{
$checkIP =array ($_server[' remote_addr ');//for
}
$insert =serialize ($checkIP);
mysql_query ("UPDATE $tableName SET total_votes= '". $added. "', total_value= '". $sum. "', used_ips= '. $insert." " WHERE id= ' ". $_get[' id ']." ' ";
echo "<div class=\" rating\ "><p>rating: <strong>". @number_format ($sum/$added, 2). " </strong> {". $added." ". $tense." Cast} <span>thank for your vote!</span></p></div> ";//show the updated value of the Vote
}else{
>4. Visitor Scoring Program
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<title>css:star rater example</title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<link href= "Styles2-1.css" rel= "stylesheet" type= "Text/css" media= "All" >
<body>
<div class= "rating" >
<p>how Clear is this tutorial?</p>
<ul class= "Star-rating" >
<li class= "current-rating" style= "width:<?php Echo @number_format ($current _rating/$count, 2) *20?>px;" >current rating</li>
<li><a href= "<?php echo $_server[' php_self '". "?". $_get[' section '. "&id=". $_get[' id ']. "&vote=1";? > "title=" Rate this 1 star out of 5 "class=" One-star >1</a></li>
<li><a href= "<?php echo $_server[' php_self '". "?". $_get[' section '. "&id=". $_get[' id ']. "&vote=1";? > "title=" Rate this 2 stars out of 5 "class=" Two-stars >2</a></li>
<li><a href= "<?php echo $_server[' php_self '". "?". $_get[' section '. "&id=". $_get[' id ']. "&vote=1";? > "title=" Rate this 3 stars out of 5 "class=" Three-stars >3</a></li>
<li><a href= "<?php echo $_server[' php_self '". "?". $_get[' section '. "&id=". $_get[' id ']. "&vote=1";? > "title=" Rate this 4 stars out of 5 "class=" Four-stars >4</a></li>
<li><a href= "<?php echo $_server[' php_self '". "?". $_get[' section '. "&id=". $_get[' id ']. "&vote=1";? > "title=" Rate this 5 stars out of 5 "class=" Five-stars >5</a></li>
</ul>
</body><?php
echo "<p>rating: <strong>". @number_format ($sum/$count, 2). " </strong> {". $count." ". $tense." Cast}</p></div> ";//show the current updated value of the vote
}//End Isset get vote
//end voted true, False
?> the next step is to put the results into the database, now there is no time to study, please wait for the next article or go to the far source to read!
Original: Creating a Star Rating system part (3)
Link: http://slim.climaxdesigns.com/tutorial.php?id=3
Copyright: Copyright belongs to the original author all, the translation document copyright belongs to oneself |greengnn, reprint please specify the source Www.jluvip.com/blog
We use PHP to implement
First look at the effect:http://gnn.80x86.cn/starrating