分类广告


推荐文章

  • 没有找到任何内容!
您当前的位置:中国站长下载网络编程PHP专区 → 文章内容

适合个人主页使用的php意见投票箱

  • 作者:佚名    来源:不详    发布时间:2006-2-26 2:02:08
  • 字体大小:
对于各位版主来说自己的主页是否受欢迎、哪些方面受欢迎、哪些方面有待改进等等都是很有用的信息。在自己的主页上放一个意见投票箱可以及时收集访客的意见对网站的建设会有很大帮助。下面是一个用PHP编写的意见投票箱页面每次投票后会在本页刷新显示各种选票的数目和所占的百分比。



----------------------vote.php------------------------------

<html>

<head>

<title>请您投票</title>

</head>

<body bgcolor = "#FFFFCC">



<?

if(isset($Submit)) //如果有新内容提交

{

if(!file_exists("voterec.txt"))

{

//各种选票数目都是0

$voterec = array(0, 0, 0, 0, 0);

}

else

{

//读出投票记录

$voterec = file("voterec.txt");

}

//更新投票记录

$voterec[$vote - 1] += 1;

//写入新的投票记录

$fp = fopen("voterec.txt", "w+");

$total = 0;

for($i = 0; $i < 5; $i ++)

{

$voterec[$i] = chop($voterec[$i]);

$total += $voterec[$i];

fwrite($fp, $voterec[$i]."\r\n");

}

fclose($fp);

}

?>



<form name="voteform" action="vote.php" method="post" >

<p>您觉得本站的内容</p>

<p>

<input type="radio" name="vote" value="1">

很好
<?echo $voterec[0]."人,占".(100 * bcdiv($voterec[0], $total, 4))."%"?></p>

<p>

<input type="radio" name="vote" value="2">

较好
<?echo $voterec[1]."人,占".(100 * bcdiv($voterec[1], $total, 4))."%"?></p>

<p>



<input type="radio" name="vote" value="3" checked>

一般
<?echo $voterec[2]."人,占".(100 * bcdiv($voterec[2], $total, 4))."%"?></p>

<p>

<input type="radio" name="vote" value="4">

较差
<?echo $voterec[3]."人,占".(100 * bcdiv($voterec[3], $total, 4))."%"?></p>

<p>

<input type="radio" name="vote" value="5">

很差
<?echo $voterec[4]."人,占".(100 * bcdiv($voterec[4], $total, 4))."%"?></p>

<p>

<input type="submit" name="Submit" value="提交意见">

</p>

</form>

</body>

</html>
<