Sondage sans BDD

Sondage sans BDD - HTML/CSS - Programmation

Marsh Posté le 24-06-2010 à 12:33:15    

Voici j'ai travailler ce code
dites moi ce que vous en pensez !
 

Spoiler :


 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript">
function getVote(int)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP" );
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("poll" ).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","poll_vote.php?vote="+int,true);
xmlhttp.send();
}
</script>
</head>
<body>
 
<div id="poll">
<h3>Do you like PHP and AJAX so far?</h3>
<form>
Yes:
<input type="radio" name="vote" value="0" onclick="getVote(this.value)" />
<br />No:
<input type="radio" name="vote" value="1" onclick="getVote(this.value)" />
<br />Maybe :
<input type="radio" name="vote" value="1" onclick="getVote(this.value)" />
</form>
</div>
 
</body>
</html>
 
 
 
<?php
$vote = $_REQUEST['vote'];
 
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
 
//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];
$no = $array[2];
 
if ($vote == 0)
  {
  $yes = $yes + 1;
  }
if ($vote == 1)
  {
  $no = $no + 1;
  }
if ($vote == 2)
  {
  $no = $no + 1;
  }
 
//insert votes to txt file
$insertvote = $yes."||".$no;
$fp = fopen($filename,"w" );
fputs($fp,$insertvote);
fclose($fp);
?>
 
<h2>Result:</h2>
<table>
<tr>
<td>Yes:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($yes/($no+$yes+$maybe),3)); ?>'
height='20'>
<?php echo(100*round($yes/($no+$yes+$maybe),3)); ?>%
</td>
</tr>
<tr>
<td>No:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($no/($no+$yes+$maybe),3)); ?>'
height='20'>
<?php echo(100*round($no/($no+$yes+$maybe),3)); ?>%
</td>
</tr>
</tr>
<tr>
<td>Maybe:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($no/($no+$yes+$maybe),3)); ?>'
height='20'>
<?php echo(100*round($no/($no+$yes+$maybe),3)); ?>%
</td>
</tr>
 
</table>
 
 


 
est-il correct ?
merci
 

Reply

Marsh Posté le 24-06-2010 à 12:33:15   

Reply

Marsh Posté le 24-06-2010 à 14:53:03    

que c'est programmé n'importe comment, mais qu'est-ce que ça peut faire :/ Ici, c'est la cat programmation, donc on répond à des questions précise sur des pbs à résoudre.
 
ps : pourquoi t'as utilisé la balise spoiler au lieu de code pour poster ton code :??:


---------------
Astres, outil de help-desk GPL : http://sourceforge.net/projects/astres, ICARE, gestion de conf : http://sourceforge.net/projects/icare, Outil Planeta Calandreta : https://framalibre.org/content/planeta-calandreta
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed