par
BioSs » 18 nov. 2007, 17:55
Salut à tous,
J'ai un problème dans mon script mais je ne trouve pas la solution...
Pour moi tout est correct mais apparement non
function sondage ($titre, $question, $reponse1, $reponse2, $reponse3, $reponse4, $nb_max_votes) {
// INFORMATIONS SUR LE SONDAGE
// $titre = 'sondage'; // = nom du fichier dans lequel est stocké les votes
// $question = 'Comment trouvez-vous ce site ?';
$reponse[1] = $reponse1;
$reponse[2] = $reponse2;
$reponse[3] = $reponse3;
$reponse[4] = $reponse4;
// $nb_max_votes = 0; // 0 si illimité
// MODIFICATION DU SONDAGE
$choix = "4";
if (isset($_GET['vote']))
{
if(empty($_COOKIE['sondage'.$$titre.'']) && !isset($_COOKIE['sondage'.$$titre.''])){
$resultats = @fopen("sondage".$titre.".txt", "r+") or die('Erreur d\'ouverture de fichier');
$vote = $_GET['vote'];
for ($numero = 1; $numero <= $choix; $numero ++)
{
$ligne[$numero] = (int) @fgets($resultats);
if ($numero == $vote)
{
$ligne[$numero] ++;
}
if (isset($donnees_votes))
{
$donnees_votes = $donnees_votes . "\n" . $ligne[$numero];
$nb_votes += $ligne[$numero]; // comptage du nombre de votes
}
else
{
$donnees_votes = $ligne[$numero];
$nb_votes = (int) $ligne[$numero];
}
}
fseek ($resultats, 0);
if($nb_votes<=$nb_max_votes OR $nb_max_votes==0)
fputs ($resultats, $donnees_votes); // écriture des données
fclose($resultats);
}
}
// LECTURE DU SONDAGE
$resultats = @fopen("sondage".$titre.".txt", "r") or die('Erreur d\'ouverture de fichier');
$numero = 1;
while ($numero <= $choix) // attribution d'un nombre pour chaque vote à l'array $resultat[]
{
$resultat[$numero] = fgets($resultats);
if ($resultat[$numero] == NULL) // on remplace les lignes vides du fich txt par 0
{
$resultat[$numero] = 0;
}
$numero ++;
}
$total_votes = 0; // calcul du total des votes
foreach($resultat as $nb_resultat) $total_votes += $nb_resultat;
if ($total_votes == 0) // éviter la division par 0
{
$total_votes = 1;
}
$numero = 1;
while ($numero <= $choix) // transformation du nombre de vote en pourcentages
{
$pourcentage[$numero] = $resultat[$numero] / $total_votes * 100;
$numero ++;
}
$long_max_bloc = 200; // longueur maximale du curseur pour un vote en pixels
// affichage des barres et du nombre de votes
$numero = 1;
if(empty($_COOKIE['sondage'.$$titre.'']) && !isset($_COOKIE['sondage'.$$titre.''])){
echo ('<div class="sondaffeu"><div class="titresondage" align="center">'. $question . '</div><br /><form action="http://'.$_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'].'" method="GET"> ');
while ($numero <= $choix)
{
if($resultat[$numero]>1){ $votess="s"; } else { $votess=""; }
echo ('<div class="choix"><label> <input class="textInput" type="radio" name="vote" value="' . $numero . '" />'. $reponse[$numero] .'</label>
<br /> <img src="../images/01.png" height="12" width="3"/><img src="../images/02.png" height="12" width="' . $pourcentage[$numero] / 100 * $long_max_bloc . '" alt="'.round($pourcentage[$numero]).'%" /><img src="../images/03.png" height="12" width="3"/><br />
<span style="font-size:80%;"><strong> ' . $resultat[$numero] . ' vote'.$votess.' ('.round($pourcentage[$numero]).'%)</strong></span></div><br>');
// echo ($pourcentage[$numero] . '%');
$numero ++;
}
echo ('<div align="center"><input class="textInput" type="submit" value="Voter"></div>');
} else {
echo ('<div class="sondaffeu"><div align="left"><a href="javascript:affmas();"><img id="tap" name="tap" src="../images/downs.gif" align="absmiddle"/></a> <a href="javascript:affmas();">'. $question . '</a></div><div id="choix" style="display: none;"><br /><form action="http://'.$_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'].'">');
while ($numero <= $choix)
{
if($resultat[$numero]>1){ $votess="s"; } else { $votess=""; }
echo ('<div class="choix"><label> '. $reponse[$numero] .'</label>
<br /> <img src="../images/01.png" height="12" width="3"/><img src="../images/02.png" height="12" width="' . $pourcentage[$numero] / 100 * $long_max_bloc . '" alt="'.round($pourcentage[$numero]).'%" /><img src="../images/03.png" height="12" width="3"/><br />
<span style="font-size:80%;"><strong> ' . $resultat[$numero] . ' vote'.$votess.' ('.round($pourcentage[$numero]).'%)</strong></span></div><br>');
// echo ($pourcentage[$numero] . '%');
$numero ++;
}
}
echo ('</form></div></div>');
fclose($resultats);
///== Par Yvan0|_| ==///
}
Le problème est que le vote n'est pas pris en charge : on a beau voter l'incrémentaiton du vote ne se fait pas
Quelle est le problème ?
Salut à tous,
J'ai un problème dans mon script mais je ne trouve pas la solution...
Pour moi tout est correct mais apparement non :)
[php]function sondage ($titre, $question, $reponse1, $reponse2, $reponse3, $reponse4, $nb_max_votes) {
// INFORMATIONS SUR LE SONDAGE
// $titre = 'sondage'; // = nom du fichier dans lequel est stocké les votes
// $question = 'Comment trouvez-vous ce site ?';
$reponse[1] = $reponse1;
$reponse[2] = $reponse2;
$reponse[3] = $reponse3;
$reponse[4] = $reponse4;
// $nb_max_votes = 0; // 0 si illimité
// MODIFICATION DU SONDAGE
$choix = "4";
if (isset($_GET['vote']))
{
if(empty($_COOKIE['sondage'.$$titre.'']) && !isset($_COOKIE['sondage'.$$titre.''])){
$resultats = @fopen("sondage".$titre.".txt", "r+") or die('Erreur d\'ouverture de fichier');
$vote = $_GET['vote'];
for ($numero = 1; $numero <= $choix; $numero ++)
{
$ligne[$numero] = (int) @fgets($resultats);
if ($numero == $vote)
{
$ligne[$numero] ++;
}
if (isset($donnees_votes))
{
$donnees_votes = $donnees_votes . "\n" . $ligne[$numero];
$nb_votes += $ligne[$numero]; // comptage du nombre de votes
}
else
{
$donnees_votes = $ligne[$numero];
$nb_votes = (int) $ligne[$numero];
}
}
fseek ($resultats, 0);
if($nb_votes<=$nb_max_votes OR $nb_max_votes==0)
fputs ($resultats, $donnees_votes); // écriture des données
fclose($resultats);
}
}
// LECTURE DU SONDAGE
$resultats = @fopen("sondage".$titre.".txt", "r") or die('Erreur d\'ouverture de fichier');
$numero = 1;
while ($numero <= $choix) // attribution d'un nombre pour chaque vote à l'array $resultat[]
{
$resultat[$numero] = fgets($resultats);
if ($resultat[$numero] == NULL) // on remplace les lignes vides du fich txt par 0
{
$resultat[$numero] = 0;
}
$numero ++;
}
$total_votes = 0; // calcul du total des votes
foreach($resultat as $nb_resultat) $total_votes += $nb_resultat;
if ($total_votes == 0) // éviter la division par 0
{
$total_votes = 1;
}
$numero = 1;
while ($numero <= $choix) // transformation du nombre de vote en pourcentages
{
$pourcentage[$numero] = $resultat[$numero] / $total_votes * 100;
$numero ++;
}
$long_max_bloc = 200; // longueur maximale du curseur pour un vote en pixels
// affichage des barres et du nombre de votes
$numero = 1;
if(empty($_COOKIE['sondage'.$$titre.'']) && !isset($_COOKIE['sondage'.$$titre.''])){
echo ('<div class="sondaffeu"><div class="titresondage" align="center">'. $question . '</div><br /><form action="http://'.$_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'].'" method="GET"> ');
while ($numero <= $choix)
{
if($resultat[$numero]>1){ $votess="s"; } else { $votess=""; }
echo ('<div class="choix"><label> <input class="textInput" type="radio" name="vote" value="' . $numero . '" />'. $reponse[$numero] .'</label>
<br /> <img src="../images/01.png" height="12" width="3"/><img src="../images/02.png" height="12" width="' . $pourcentage[$numero] / 100 * $long_max_bloc . '" alt="'.round($pourcentage[$numero]).'%" /><img src="../images/03.png" height="12" width="3"/><br />
<span style="font-size:80%;"><strong> ' . $resultat[$numero] . ' vote'.$votess.' ('.round($pourcentage[$numero]).'%)</strong></span></div><br>');
// echo ($pourcentage[$numero] . '%');
$numero ++;
}
echo ('<div align="center"><input class="textInput" type="submit" value="Voter"></div>');
} else {
echo ('<div class="sondaffeu"><div align="left"><a href="javascript:affmas();"><img id="tap" name="tap" src="../images/downs.gif" align="absmiddle"/></a> <a href="javascript:affmas();">'. $question . '</a></div><div id="choix" style="display: none;"><br /><form action="http://'.$_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'].'">');
while ($numero <= $choix)
{
if($resultat[$numero]>1){ $votess="s"; } else { $votess=""; }
echo ('<div class="choix"><label> '. $reponse[$numero] .'</label>
<br /> <img src="../images/01.png" height="12" width="3"/><img src="../images/02.png" height="12" width="' . $pourcentage[$numero] / 100 * $long_max_bloc . '" alt="'.round($pourcentage[$numero]).'%" /><img src="../images/03.png" height="12" width="3"/><br />
<span style="font-size:80%;"><strong> ' . $resultat[$numero] . ' vote'.$votess.' ('.round($pourcentage[$numero]).'%)</strong></span></div><br>');
// echo ($pourcentage[$numero] . '%');
$numero ++;
}
}
echo ('</form></div></div>');
fclose($resultats);
///== Par Yvan0|_| ==///
}
[/php]
Le problème est que le vote n'est pas pris en charge : on a beau voter l'incrémentaiton du vote ne se fait pas
Quelle est le problème ?