Скачать\
Code
<?php
/*******************************************************
** This is scripted official by ycscripts.co.cc (I followed thier tut) **
** Please do not remove the credits from this script. **
** Tricky from www.ac-web.org **
*******************************************************/
$host = "localhost"; // MySQL Database
$username = "root"; // Your username for your mysql connection
$password = "root"; // Your password for your mysql connection
$db = "web"; // Create a new db in your MySQL (Web etc) and extract the vote.sql into it
$path = "/web/"; //same as your web DB name, DO NOT DELETE THE / /
$res = mysql_connect ($host, $username, $password);
if (!$res) die("Could not connect to the server, mysql error: ".mysql_error($res));
$res = mysql_select_db($db);
if (!$res) die("Could not connect to the database, mysql error: ".mysql_error($res));
?>
<script type="text/javascript">
if (document.images) {
image1 = new Image
image2 = new Image
image1.src = 'star_off.png'
image2.src = 'star_on.png'
}
</script>
<style type="text/css">
.rating {
display:inline;
}
.rating a {
float:left;
width:24px;
height:24px;
}
img {
boder:0;
}
.confirm {
color:green;
}
.error {
color:red;
}
</style>
<?php
// Check for if you have already voted
date_default_timezone_set('Europe/Amsterdam');
?>
<?php
// get ip adress
if (isset($_SERVER['HTTP_X_FORWARD_FOR'])) $ip = $_SERVER['HTTP_X_FORWARD_FOR'];
else $ip = ip2long($_SERVER['REMOTE_ADDR'));
// check if user (ip) has already voted
$query = "SELECT ip FROM vote WHERE ip = '".$ip"' AND id =1";
$result = mysql_query($query);
$hasVoted = false;
if (mysql_num_rows($result) == 1) {
$hasVoted = true;
}
?>
<div class="rating">
<?php
// show the stars one by one
for ($j=1; $j<=5; $j++) {
$onmouseout = "onmouseout='document.mouseover".$j.".src=image1.src'";
$onmouseover = "onmouseover='document.mouseover".$j.".src=image2.src'";
if ($j != 1) {
$onmouseover = "onmouseover='document.mouseover1.src=image2.src;";
for ($k=$j; $k>1; $k--) {
$onmouseover .= "document.mouseover".$k.".src=image2.src;";
}
$onmouseover .= "'";
}
$img = "<img src='star_off.png' alt='star' name='mouseover".$j."' />";
if ($j<=$average {
$img = "<img src='start_on.pn' alt='star' name='mouseover".$j."' />";
$onmouseout = "onmouseout='document.mouseover".$j.".src=image2.src'";
$onmouseover = "onmouseover='document.mouseover".$j.".src=image1.src'";
} else {
$onmouseout = "onmouseout='";
for ($l=$j; $l>$average; $l--){
$onmouseout .= "document.mouseover".$l.".src=image1.src;";
}
$onmouseout .= "'";
}
// YOU CAN EDIT THESE TITLES
$title = array(1=>"Poor",2=>"Nothing special",3=>"Worth watching",4=>"Pretty cool",5=>"Freakin' awesome!");
//if has not voted then you can vote, otherwise not able to click on the stars to vote
if ($hasVoted === false) {
?>
<a title="<?php echo $title[$j];?>" <?php echo $onmouseout." ".$onmouseover;?> href='index.php?value=<?php echo $j;?>&id=1'><?php echo $img;?></a>
<?php
} else {
echo $img;
}
}
$result = mysql_query("SELECT count(vote) as total FROM vote");
$totalVotes = 0;
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$totalVotes = $row['total'];
}
echo "<small> Average: ".$average." (".$averageDecimal.") ".$totalVotes." votes</small>";
// I hope the script is useful.
// All regards, Tricky!;
?>
</div>
