GreyNodes/database_connection.php
//database_connection.php
$connect = new PDO('mysql:host=localhost;dbname=testing', 'root', '');
?>
GreyNodes/fetch_poll_data.php
//fetch_poll_data.php
include('database_connection.php');
$php_framework = array("HTML", "CSS", "JAVASCRIPT", "REACTJS", "ANGULAR");
$total_poll_row = get_total_rows($connect);
$output = '';
if($total_poll_row > 0)
{
foreach($php_framework as $row)
{
$query = "SELECT * FROM tbl_poll WHERE php_framework = '".$row."'";
$statement = $connect->prepare($query);
$statement->execute();
$total_row = $statement->rowCount();
$percentage_vote = round(($total_row/$total_poll_row)*100);
$progress_bar_class = '';
if($percentage_vote >= 40)
{
$progress_bar_class = 'progress-bar-success';
}
else if($percentage_vote >= 25 && $percentage_vote < 40)
{
$progress_bar_class = 'progress-bar-info';
}
else if($percentage_vote >= 10 && $percentage_vote < 25)
{
$progress_bar_class = 'progress-bar-warning';
}
else
{
$progress_bar_class = 'progress-bar-danger';
}
$output .= '
'.$percentage_vote.' % programmer like '.$row.' PHP Framework
';
}
}
echo $output;
function get_total_rows($connect)
{
$query = "SELECT * FROM tbl_poll";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
?>
GreyNodes/index.php
//index.php
?>
Live Poll System in PHP Mysql using Ajax