本文を表示
<ul id="enq_graph">
<?php
try {
$pdo = new PDO("sqlite:/var/www/paralegal-web.jp/setting/enq/q18.sqlite3");
$sth = $pdo->query('SELECT COUNT(id) FROM answers');
$total_votes = $sth->fetchColumn();
$sth = $pdo->query('SELECT answer, COUNT(id) AS votes FROM answers GROUP BY answer ORDER BY COUNT(id) DESC');
// var_dump($row);
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$percent = 0;
$percent = round($row['votes'] / $total_votes * 100, 2);
$option_name = '';
$sth2 = $pdo->query('SELECT option_name FROM options WHERE id = ?');
$sth2->execute(array($row['answer']));
$option_name = $sth2->fetchColumn();
// var_dump($option_name);
echo "\t\t\t" . '<li>投票数: ' . "\n";
echo "\t\t\t\t" . '<span class="total-votes">' . $row['votes'] . '</span>票 「' . $option_name . "」\n";
echo "\t\t\t\t" . '<br />' . "\n";
echo "\t\t\t\t" . '<div class="results-bar" style="width: ' . $percent . '%;">' . "\n";
echo "\t\t\t\t" . $percent . '%' . "\n";
echo "\t\t\t" . '</div></li>' . "\n";
}
} catch (PDOException $e){
var_dump($e->getMessage());
}
?>
</ul>
<style type="text/css">
table.table { width: 100%;
border: 1px #E3E3E3 solid;
border-collapse: collapse;
border-spacing: 0;
}table.table th { padding: 5px;
border: #E3E3E3 solid;
border-width: 0 0 1px 1px;
background: #F5F5F5;
font-weight: bold;
line-height: 120%;
text-align: center;
}table.table td { padding: 5px;
border: 1px #E3E3E3 solid;
border-width: 0 0 1px 1px;
text-align: center;
}
</style>
<div id="enq_note">
<h6>総投票数: <span class="total-votes"><?php echo $total_votes; ?>票</span></h6>
<ul>
<li><a href="/paracomi/enq/purpose.php" target="window_name" onClick="disp('/paracomi/enq/purpose.php')">当アンケートの目的</a></li>
<li><a href="/paracomi/enq/q18.php">アンケートに投票する(抽選でAmazonギフト券をプレゼント)</a></li>
</ul>
</div>