
■【アンケート】就業規則はありますか?
- 
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" . '
 - 投票数: ' . "\n";
        echo "\t\t\t\t" . '' . $row['votes'] . '票 「' . $option_name . "」\n";
        echo "\t\t\t\t" . '
' . "\n"; echo "\t\t\t\t" . ' ' . "\n";
    }
} catch (PDOException $e){
    var_dump($e->getMessage());
}
?>