【www.gdgbn.com--jquery】
代码如下/* database config */
$db_host = "";
$db_user = "";
$db_pass = "";
$db_database = "";
/* end config */
$link = mysql教程_connect($db_host,$db_user,$db_pass) or die("unable to establish a db connection");
mysql_select_db($db_database,$link);
mysql_query("set names utf8");
?>
css教程" href="demo.css" />
<script type="text/网页特效" src="</script">http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="</script">http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="script.js"></script>
// checking whether the user has voted today:
$voted=false;
$vcheck=mysql_query(" select 1 from sort_votes
where ip="".$_server["remote_addr"].""
and date_submit=curdate()");
if(mysql_num_rows($vcheck)==1)
$voted=true;
// if we are not on the data.php?results page:
if(!array_key_exists("results",$_get))
{
echo "
- ";
- ">
" width="100" height="100" alt="" />
" target="_blank" title="open it in a new window!">
submit poll
view the results
}
else require "results.php";
// the above require saves us from having to style another separate page?>
results.phpif($_post["sortdata"])
{
// the data arrives as a comma-separated string,
// so we extract each post ids:
$data=explode(",",str_replace("li","",$_post["sortdata"]));// getting the number of objects
list($tot_objects) = mysql_fetch_array(mysql_query("select count(*) from sort_objects"));if(count($data)!=$tot_objects) die("wrong data!");
foreach($data as $k=>$v)
{
// building the sql query:
$str[]="(".(int)$v.",".($tot_objects-$k).")";
}
$str = "values".join(",",$str);
// this will limit voting to once a day per ip:
mysql_query(" insert into `sort_votes` (ip,date_submit,dt_submit)
values ("".$_server["remote_addr"]."",now(),now())");// if the user has not voted before today:
if(mysql_affected_rows($link)==1)
{
mysql_query(" insert into `sort_objects` (id,votes) ".$str."
on duplicate key update votes = votes+values(votes)");
}
}// selecting the sample tutorials and ordering
// them by the votes each of them received:
$res = mysql_query("select * from sort_objects order by votes desc");$maxvote=0;
$bars=array();while($row=mysql_fetch_assoc($res))
{
$bars[]=$row;
// storing the max vote, so we can scale the bars of the chart:
if($row["votes"]>$maxvote) $maxvote = $row["votes"];
}$barstr="";
// the colors of the bars:
$colors=array("#ff9900","#66cc00","#3399cc","#dd0000","#800080");foreach($bars as $k=>$v)
{
// buildling the bar string:
$barstr.="
".$v["short"]."
";
}// the total number of votes cast in the poll:
list($totvotes) = mysql_fetch_array(mysql_query("select count(*) from sort_votes"));?>
go back
votes
源码下载
http://down.111cn.net/down/code/php/toupiaodiaocha/2010/1028/21481.html
// showing the tutorials by random
$res = mysql_query("select * from sort_objects order by rand()");
while($row=mysql_fetch_assoc($res))
{?>