Pages vues depuis 05/06/2021 : 1 779 453
Index du forum »» Demo »» pollboth.php a la racine
function pollResults(int $pollID): void
{
global $NPDS_Prefix, $maxOptions, $setCookies;
if (!isset($pollID) OR empty($pollID)) $pollID = 1;
$result = sql_query("SELECT pollID, pollTitle, timeStamp FROM ".$NPDS_Prefix."poll_desc WHERE pollID='$pollID'");
list(,$pollTitle) = sql_fetch_row($result);
echo '
<h3 class="my-3">'.$pollTitle.'</h3>';
$result = sql_query("SELECT SUM(optionCount) AS SUM FROM ".$NPDS_Prefix."poll_data WHERE pollID='$pollID'");
list($sum) = sql_fetch_row($result);
echo '
<h4><span class="badge bg-secondary">'.$sum.'</span> '.translate("Résultats").'</h4>';
for ($i = 1; $i <= $maxOptions; $i++) {
$result = sql_query("SELECT optionText, optionCount, voteID FROM ".$NPDS_Prefix."poll_data WHERE (pollID='$pollID') AND (voteID='$i')");
$object = sql_fetch_assoc($result);
// php8
if (!is_null($object)) {
$optionText = $object['optionText'];
$optionCount = $object['optionCount'];
} else {
$optionText = '';
$optionCount = 0;
}
// php8
if ($optionText!= "") {
if ($sum) {
$percent = 100*$optionCount/$sum;
$percentInt = (int)$percent;
} else {
$percentInt = 0;
}
echo '
<div class="row">
<div class="col-sm-5 mt-3">'.aff_langue($optionText).'</div>
<div class="col-sm-7">
<span class="badge bg-secondary mb-1">'.wrh($optionCount).'</span>
<div class="progress">
<span class="progress-bar" role="progressbar" aria-valuenow="'.$percentInt.'%" aria-valuemin="0" aria-valuemax="100" style="width:'.$percentInt.'%;" title="'.$percentInt.'%" data-bs-toggle="tooltip"></span>
</div>
</div>
</div>';
}
}
echo '<br />';
echo '<p class="text-center"><b>'.translate("Nombre total de votes: ").' '.$sum.'</b></p><br />';
if ($setCookies>0) {
echo '<p class="text-danger">'.translate("Un seul vote par sondage.").'</p>';
}
}