1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <?php
require('configuration.php');
//On prend l'id le plus grand
$nombreEntrees = mysql_query("SELECT MAX(id) AS nbre_entrees FROM sondage") or die(mysql_error());
$numeroDuSondage = mysql_fetch_assoc($nombreEntrees);
//On sélectionne la question et les choix
$req="SELECT question, proposition1, proposition2, proposition3 FROM sondage WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'";
$MySQL_infos = mysql_query($req) or die(mysql_error());
$infos = mysql_fetch_array($MySQL_infos);
//On sélectionne le nombre de votes
$MySQL_votes = mysql_query("SELECT resultats1, resultats2, resultats3 FROM sondage WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'") or die(mysql_error());
$votes = mysql_fetch_assoc($MySQL_votes);
//script pour ajouter les votes
$prop = "prop";
$resultat = "resultats";
$fin = false;
if(isset($_POST['sondage']))
{
for($i = 1; $i <= 5 && !$fin; $i++)
{
if($_POST['sondage'] == $prop . $i)
{
$votes[$resultat . $i] ++;
mysql_query("UPDATE sondage SET " . $resultat . $i ." = '" . $votes[$resultat . $i] . "' WHERE id = '" . $numeroDuSondage['nbre_entrees'] . "'") or die(mysql_error());
$fin = true;
}
}
}
?>
<?php
// pourcentage des votes en moide graphique et compte
// On recupere les nombre total de votes resultat1
$query = "SELECT count(resultats1) as nbre_entrees FROM ".$table;
$row = mysql_query($query);
while($data = mysql_fetch_array($row))
$resultat1 = $data["nbre_entrees"];
// On recupere les nombre total de votes resultat1
$query2 = "SELECT count(resultats2) as nbre_entrees FROM ".$table;
$row2 = mysql_query($query2);
while($data2 = mysql_fetch_array($row))
$resultat2 = $data2["nbre_entrees"];
// On recupere les nombre total de votes resultat1
$query3 = "SELECT count(resultats3) as nbre_entrees FROM ".$table;
$row3 = mysql_query($query3);
while($data3 = mysql_fetch_array($row3))
$resultat3 = $data3["nbre_entrees"];
//on compte le total de pourcentage
for($i=0;$i<sizeof($votes);$i++)
{
// Pourcentage choix1
$query = "SELECT count(*) nbre_entrees FROM ".$table." ";
$row = mysql_query($query);
while($data = mysql_fetch_array($row))
echo($resultats1 . " - " . $resultats2 . " - " . $resultats3);
$pourcentage1 = $resultats1 / ($resultats1 + $resultats2 + $resultats3) *100;
}
echo '<pre>';
var_dump($resultat1,$resultat2,$resultat3);
echo '</pre>';
?>
<!-- formulaire -->
<form method="post">
<?php echo "" . $infos['question'] . ""; ?><br />
<?php echo $infos['proposition1']; ?><br />
<input type="radio" name="sondage" value="prop1" id="prop1" /><label for="prop1"> <img src='black.jpg'><?php echo $pourcentage1 . " %"; ?> </label><br />
<?php echo $infos['proposition2']; ?><br />
<input type="radio" name="sondage" value="prop2" id="prop2" /> <label for="prop2"> <img src='blue.jpg'> <?php echo $votes['resultats2'] . " %"; ?></label><br />
<?php echo $infos['proposition3']; ?><br />
<input type="radio" name="sondage" value="prop3" id="prop3" /> <label for="prop3"> <img src='copper.jpg'><?php echo $votes['resultats3'] . " %"; ?></label><br />
<input type="submit" value="Voter !"/>
</form> |