·网站首页·联系我们·在线留言
东莞网站建设
东汇设计 网站建设 成功案例 网站优化 网站推广 网络营销 域名注册 虚拟主机 网站建设知识
 
  网站建设知识  
  东汇服务热线:13650104846  
  网站域名  

  虚拟主机  

  网站设计  

  网页配色  

  动画设计  

  网站维护  

  程序asp  

  程序asp.net  

  程序php  

  程序jsp  

  韩国网站分析  

 
 
  您现在位置:东莞网站建设 >> 东莞网站建设知识 >> 程序php >> 正文
PHP投票系统处理方法
发布日期:08-07-21 19:13:49  点击次数:[

PHP投票系统处理方法 
<? 
$status=0; 
if(isset($polled)&&($polled=="c-e")){ 
$status=1; 

#echo "$status"; 
if(isset($poll)&&($status==0)){ 
setcookie("polled","c-e",time()+86400,"/");#time=24h 

?> 
<html> 
<head> 
<title>新版页面调查</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<style type="text/css"> 
<!-- 
.tb { border="1" bordercolor="#009933" cellspacing="0" font-size: 9pt; color: #000000} 
.head { font-family: "宋体"; font-size: 12pt; font-weight: bold; color: #009933; text-decoration: none} 
.pt9 { font-size: 9pt} 
a.p9:link { font-size: 9pt; color: #000000; text-decoration: none} 
a.p9:visited { font-size: 9pt; color: #000000; text-decoration: none } 
a.p9:hover { font-size: 9pt; color: #FF0000; text-decoration: underline} 
a.p9:active { font-size: 9pt; color: #FF0000; text-decoration: underline } 
--> 
</style> 
</head> 
<body bgcolor="#FFFFFF"> 
<div class="head">与旧版页面相比较您觉得新版页面:</div><br> 
<? 
if(!isset($submit)){ 
?> 
<form action="myPolls.php3" method="get"> 
<input type="radio" name="poll_voteNr" value="1" checked > 
<span class="pt9">信息量更大</span> <br> 
<input type="radio" name="poll_voteNr" value="2" > 
<span class="pt9">网页更精美</span> <br> 
<input type="radio" name="poll_voteNr" value="3" > 
<span class="pt9">没什么改进</span> <br> 
<input type="radio" name="poll_voteNr" value="4" > 
<span class="pt9">其它</span> <br> 
<input type="submit" name="submit" value="OK"> 
<input type="hidden" name="poll" value="vote"> 
<A HREF="myPolls.php3?submit=OK" class="p9">查看调查结果</A> 
</form> 
<? 
/* 
如果想增加其它的选项可直接加上即可 
*/ 
}else{ 
$descArray=array(1=>"信息量更大", 
2=>"网页更精美", 
3=>"没什么改进", 
4=>"其它" 
); 
$poll_resultBarHeight = 9; // height in pixels of percentage bar in result table 
$poll_resultBarScale = 1; // scale of result bar (in multiples of 100 pixels) 
$poll_tableHeader="<table border=1 class="tb">"; 
$poll_rowHeader="<tr>"; 
$poll_dataHeader="<td align=center>"; 
$poll_dataFooter="</td>"; 
$poll_rowFooter="</tr>"; 
$poll_tableFooter="</table>"; 
$coutfile="data.pol"; 
$poll_sum=0; 

// read counter-file 
if (file_exists( $coutfile)) 

$fp = fopen( $coutfile, "rt"); 
while ($Line = fgets($fp, 10)) 

// split lines into identifier/counter 
if (ereg( "([^ ]*) *([0-9]*)", $Line, $tmp)) 

$curArray[(int)$tmp[1]] = (int)$tmp[2]; 
$poll_sum+=(int)$tmp[2]; 


// close file 
fclose($fp); 
}else{// 
for ($i=1;$i<=count($descArray);$i++){ 
$curArray[$i]=0; 


if(isset($poll)){ 
$curArray[$poll_voteNr]++; 
$poll_sum++; 

echo $poll_tableHeader; 

// cycle through all options编历数组 
reset($curArray); 
while (list($K, $V) = each($curArray)) 

$poll_optionText = $descArray[$K]; 
$poll_optionCount = $V; 
echo $poll_rowHeader; 

if($poll_optionText != "") 

echo $poll_dataHeader; 
echo $poll_optionText; 
echo $poll_dataFooter; 

if($poll_sum) 
$poll_percent = 100 * $poll_optionCount / $poll_sum; 
else 
$poll_percent = 0; 
echo $poll_dataHeader; 

if ($poll_percent > 0) 

$poll_percentScale = (int)($poll_percent * $poll_resultBarScale); 

printf(" %.2f %% (%d)", $poll_percent, $poll_optionCount); 

echo $poll_dataFooter; 

echo $poll_rowFooter; 

echo "总共投票次数:<font color=red> $poll_sum</font>"; 
echo $poll_tableFooter; 
echo "<br>"; 
echo "<input type="submit" name="Submit1" value="返回主页" onClick="javascript:location=’http://gophp.heha.net/index.html’">"; 
echo " <input type="submit" name="Submit2" value="重新投票" onClick="javascript:location=’http://gophp.heha.net/mypolls.php3’">"; 
if(isset($poll)){ 
// write counter file 
$fp = fopen($coutfile, "wt"); 
reset($curArray); 
while (list($Key, $Value) = each($curArray)) 

$tmp = sprintf( "%s %dn", $Key, $Value); 
fwrite($fp, $tmp); 

// close file 
fclose($fp); 


?> 
</body> 
</html> 
以上文章由东汇网站建设公司提供.


上一页:    下一页: 

 
 
网站导航:
网站首页|东汇设计|网站建设|网页制作|成功案例|网站优化|网站推广|域名注册|虚拟主机|企业邮局|网络营销|网站建设知识|联系我们|在线留言|网页设计

东莞网页制作 地址:东莞市南城区体育路嘉信大厦(皇胜酒店对面)4F16室 版权所有:东莞网站建设服务商-东莞市东汇设计网络公司
电话:076922064003 手机:13650104846 13559782770