//Affichage du sondage. $vote_query = doquery ("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 0,1", "sondage"); $vote = mysql_fetch_array($vote_query); $ip_query = doquery ( "SELECT * FROM {{table}} WHERE numero='".$vote['id']."' AND ip='".$_SERVER['REMOTE_ADDR']."'","sondage_ip"); $ip = mysql_num_rows($ip_query); if (!empty($vote['question'])){ $question = ' '.stripslashes($vote['question']).'

'; $bouton = '
'; }else{ $question = 'Aucun sondage'; $bouton = ''; } $sondage = $question; $nbQuestions = 4; if (!isset($_POST["sondage_x"])) { for($i=1 ; $i<=$nbQuestions ; $i++) { $check = ($i==1) ? 'checked' : ''; $champ='reponse'.$i; if(!empty($vote[$champ])) { $sondage .= ' '.stripslashes($vote[$champ]).'
'; } } $sondage .= '
'.$bouton.''; } else { for($i=1 ; $i<=$nbQuestions ; $i++) { $champ = 'resultat'.$i; if($i==$_POST['reponse']) { $update = $champ.'= '.$champ.' + 1'; } } $save_vote = doquery("UPDATE {{table}} SET $update WHERE id='".$vote['id']."'", "sondage"); $insert_ip = doquery("INSERT INTO {{table}} SET numero='".$vote['id']."', ip='".$_SERVER['REMOTE_ADDR']."'", "sondage_ip"); $sondage = 'Les résultats des votes:'; for($i=1 ; $i<=$nbQuestions ; $i++) { $champ='reponse'.$i; $nombre_vote='resultat'.$i; if(!empty($vote[$champ])) { if($vote[$nombre_vote]>1){ $pluriel = 'votes'; }else{ $pluriel = 'vote';} $sondage .= '- '.stripslashes($vote[$champ]).' ('.$vote[$nombre_vote].' '.$pluriel.')
'; } } }