作者godinx (诺兰德)
看板PHP
标题Re: [请益] 真的没办法了..
时间Fri Jan 12 23:14:50 2007
经过又试了四五个小时以後
总算可以新增资料
这是用户端的程式
<html>
<head>
<title>投票系统</title>
<head>
<body>
<CENTER><FONT SIZE='7' COLOR='#FF0000'>投票主题</FONT></CENTER><HR>
<CENTER>请问一下你(你)对这次高铁成行的看法,你给高铁局打几分
?</CENTER><BR><BR><BR>
<form method="post" action="show_poll.php">
<input type="radio" name="vote" value="Good">还不错<br />
<input type="radio" name="vote" value="soso">有点糟<br />
<input type="radio" name="vote" value="bad">太差了<br /><br />
<input type="submit" value="投票并立即开票">
</form>
</body>
伺服端的程式
<?php
$vote=$HTTP_POST_VARS['vote'];
if (!$db_conn = @mysql_connect('localhost', 'a94213066', 'a94213066'))
{
echo 'Could not connect to db<br />';
exit;
};
@mysql_select_db('a94213066');
if (!empty($vote)) // if they filled the form out, add their vote
{
$vote = addslashes($vote);
$query = "update poll_results
set num_votes = num_votes + 1
where candidate = '$vote'";
if(!($result = @mysql_query($query, $db_conn)))
{
echo 'Could not connect to db<br />';
exit;
}
};
// get current results of poll, regardless of whether they vote
$query = 'select * from poll_results';
if(!($result = @mysql_query($query, $db_conn)))
{
echo 'Could not connect to db<br />';
exit;
}
$num_candidates = mysql_num_rows($result);
// calculate total number of votes so far
$total_votes=0;
while ($row = mysql_fetch_object ($result))
{
$total_votes += $row->num_votes;
}
mysql_data_seek($result, 0);
@mysql_connect($good,$db_conn);
$good = "select num_votes from poll_results where good";
?>
我现在的方式是把值全存在同一个table里面(poll_results)
然後将栏位分成 good,soso,bad 其初始值为零
每次假如点选後案送出其值就+1
不过现在我变成不知道怎样让网页显示出来分别查询
good soso bad 的值
请问一下我应该要输入哪些程式才可以叫出我想要的值呢?
谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.22.18.92
1F:推 foxzgerald:$HTTP_POST_VARS['vote']; 可以用 $_POST['vote'];替代 01/12 23:17