he encontrado una encuesta y me gustaría que me ayudáseis a hacerla funcionar.
a ver.
encuesta
Código PHP:
CREATE TABLE encuesta (
idencuesta int(11) NOT NULL auto_increment,
pregunta char(50) not null,
respuesta1 char(20) not null,
respuesta2 char(20) not null,
valor1 TINYINT(255) NOT NULL,
total TINYINT(255) NOT NULL,
INDEX ( `idencuesta` )
)
Código PHP:
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$servidor = "pub-db.m2kcore.com";
$usuario = "cmblackriver";
$password = "xxxxx";
$base_de_datos = "cmblackriver";
$conextar=mysql_connect ($servidor,$usuario,$password);
mysql_select_db($base_de_datos);
$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
?>
<script type="text/javascript" language="JavaScript">
function resultados(){
window.open("resultados.php",""," toolbar=0,location=0,directories=0,status=0,menuba
r=0,scrollbars=0,resizable=0,width=320,height=200");
}
</script>
<form name="form1" method="post" action="<?= $PHP_SELF?>">
<table width="256" border="0" align="center" cellpadding="0" cellspacing="0" class="forumline">
<tr valign="baseline">
<td colspan="2" class="row1">
<?=$row['pregunta']; ?>
<br>
</td>
</tr>
<tr>
<td width="110">
<?=$row['respuesta1'];?>
</td>
<td width="146"><input type="radio" name="voto" value="1">
</td>
</tr>
<tr>
<td>
<?=$row['respuesta2'];?>
</td>
<td><input type="radio" name="voto" value="2"></td>
</tr>
<tr>
<td>
<?=$row['respuesta3'];?>
</td>
<td><input type="radio" name="voto" value="3"></td>
</tr>
<tr align="center">
<td height="20" colspan="2"><input type="submit" class="post"name="Submit" value="Votar" onClick=window.open("resultados.php",""," toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=320,height=200");}></td>
</tr>
</table>
<p> </p></form>
</body>
</html>
Código PHP:
<html>
<head>
<title>Resultados de la encuesta</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #FFFFDD;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
</head>
<body>
<?
$servidor = "pub-db.m2kcore.com";
$usuario = "cmblackriver";
$password = "xxxxx";
$base_de_datos = "cmblackriver";
$conextar=mysql_connect ($direccion,$usuario,$password);
mysql_select_db($base_de_datos);
//$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
//mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
$res1= round ($row['valor1']*100/$row['total'],2);
$res2= round ($row['valor2']*100/$row['total'],2);
$res3= round ($row['valor3']*100/$row['total'],2);
?>
<p>Resultados parciales de la encuesta</p>
<?=$row['pregunta']; ?><br>
<br>
<TABLE WIDTH="300" BORDER="1" ALIGN="center" BORDERCOLOR="#3097A3">
<TR>
<TD WIDTH="100"><?=$row['respuesta1']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor1"]*100/$row["total"]?>%" SRC="encuesta/barra1.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res1."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100" ><?=$row['respuesta2']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor2"]*100/$row["total"]?>%" SRC="encuesta/barra2.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res2."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100"><?=$row['respuesta3']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor3"]*100/$row["total"]?>%" SRC="encuesta/barra3.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res3."%";?> </TD>
</TR>
</TABLE>
<form name="form1" method="post" action="">
<div align="center">
<p>
<input type="submit" name="Submit" value="Cerrar Ventana" onclick="window.close();">
</p>
<p> </p>
</div>
</form>
</body>
</html>
una sugerencia, es que me ayudéis a hacer que en vez de mostrar los resultados en otra página, que haga una especie de include o "else" o alguna cosa de estas para que vea los resultados.
bueno, a ver que se puede hacer
adios y gracias
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)