2006/7/4 学籍番号 名前 |
アンケートDB enquete |
|||||||||||
| id | question | s0 | s1 | s2 | s3 | s4 | c0 | c1 | c2 | c3 | c4 |
| 1 | どのスクリプトが得意ですか | PHP | ActionScript | JavaScript | 0 | 0 | 0 | 0 | 0 | ||
| 2 | 今日のお昼はなにを食べたいですか | うな丼 | 天ざる | 上ずし | カップラーメン | 0 | 0 | 0 | 0 | 0 | |
アンケート結果表示スクリプト result.php 問題 3箇所のアンダーラインを埋めて、完成させよ。 |
<?php
//result.php
require_once($_SERVER['DOCUMENT_ROOT']."/kume/common/db_value.php");
$con=mysql_connect($DBSERVER, $DBUSER, $DBPASSWORD);
$sel=mysql_select_db($DBNAME, $con);
$sql="SELECT * FROM enquete WHERE id=1";
$rst=mysql_query($sql, $con);
$row=mysql_fetch_array($rst);
//アンケート内容を取得
$q=nl2br($row["question"]);//質問文
$s=array($row["s0"], $row["s1"], $row["s2"]);//選択肢
$c=array($row["c0"], $row["c1"], $row["c2"]);//各投票数カウンタ
$total=0;
for($i=0; $i<count($c); $i++){//全投票数計算
________________________________
}
//パーセントを計算
$p= array_fill(0, count($s), 0);//$p配列を全て0で埋める
if(_________________ !=0){
for($i=0; $i<count($c); $i++){
$p[$i]=$c[$i]*100/$total;
}
}
//棒グラフを作成
$m="<table border='0' cellspacing='0' cellpadding='2'>";
for($i=0; $i<count($c); $i++){
$m.="<tr><td>".$s[$i]."</td>";
$m.="<td>".$c[$i]."</td>";
$m.="<td><img src='bar.gif' height='8' width='".___________."'></td></tr>";
}
$m.="</table>";
mysql_free_result($rst);
$cls=mysql_close($con);
?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>アンケート結果</title></head>
<body>
<h1>アンケート結果</h1>
<?php print "<h2>$q</h2>"; ?>
<?php print $m; ?>
<p><a href="question.php">投票する</a></p>
</body>
</html>
|