Foros del Web » Programando para Internet » PHP »

No recuenta los votos

Estas en el tema de No recuenta los votos en el foro de PHP en Foros del Web. Hola tengo este codigo: Código PHP: <? mysql_connect ( 'localhost' , 'xxx' , 'xxx' )or die( 'ERROR EN LA CONEXION :' . mysql_error ()); mysql_select_db ( 'xxx' )or die( 'ERROR AL ESCOJER LA BD :' . ...
  #1 (permalink)  
Antiguo 24/06/2007, 14:52
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
No recuenta los votos

Hola tengo este codigo:

Código PHP:
<?
mysql_connect
('localhost','xxx','xxx')or die('ERROR EN LA CONEXION :'.mysql_error());
mysql_select_db('xxx')or die('ERROR AL ESCOJER LA BD :'.mysql_error());

function 
show_encuesta($id_ENCUESTA,$proteccion_IP){
// COLOCO TODAS MIS PREGUNTAS Y OPCIONES 
$encuesta[1]=array('&iquest;Que te parece el nuevo dise&ntilde;o?',array('Muy bueno','Bueno','Normal','Malo','Asqueroso'));
//END 
if (!array_key_exists($id_ENCUESTA,$encuesta)) return ('El id de la encuesta no se encuentra disponible');
else
$pregunta_de_la_encuesta array_shift($encuesta[$id_ENCUESTA]);
$opciones_de_la_encuesta array_pop ($encuesta[$id_ENCUESTA]);
if(isset(
$_POST[opcion])){
$ssqls=mysql_query('SELECT * FROM encuesta_blt WHERE ip="'.$REMOTE_ADDR.'"')or die(mysql_error());
if(
$proteccion_IP && mysql_num_rows($ssqls)>=1){
$html_encuesta='<font color="#1D59C9" face="tahoma"  size="2"><strong>Usted ya ha votado en esta encuesta</strong></font>';

}
else {
mysql_query('INSERT INTO encuesta_blt VALUES("'.$id_ENCUESTA.'","'.$_POST[opcion].'","'.$REMOTE_ADDR.'")')or die(mysql_error()); }
}

$ssql=mysql_query('SELECT * FROM encuesta_blt WHERE id_encuesta="'.$id_ENCUESTA.'"')or die(mysql_error());
$total_votos=mysql_num_rows($ssql);


// IMPRIMIR LOS RESULTADOS.
$html_encuesta.='<form action="'.$_SERVER[REQUEST_URI].'" method="POST">';
$html_encuesta.= '<font color="#666666" face="tahoma"  size="2"><strong>'.$pregunta_de_la_encuesta.'</strong></font><br>';
$html_encuesta.='<br>';
foreach(
$opciones_de_la_encuesta as $KEY => $OPCION){
$ssql=mysql_query('SELECT * FROM encuesta_blt WHERE id_encuesta="'.$id_ENCUESTA.'" and id_opcion="'.$KEY.'"')or die(mysql_error());
$votos_x_opcion=mysql_num_rows($ssql);
$estimar_porcentaje= @round($votos_x_opcion*100/$total_votos,1);
$html_encuesta.= '<table style="width: 200px; height: 20px; border: 0px;"><tr style="display: inline;"><td style="display: inline; text-align: left; width: 20px;"><input name="opcion" type="radio" value="'.$KEY.'"';
if(
$_POST[opcion]==$KEY && isset($_POST[opcion])){$html_encuesta.='checked'; }
$html_encuesta.= '></td><td style="display: inline; text-align: left;">'.$OPCION.' '.$estimar_porcentaje.' %</td> <strong> <td style="display: inline; width: 50px; text-align: left;"><div style="background-color:#1D59C9; border: 1px solid #999999; font-size: 5px; width:'.$estimar_porcentaje.'%;"></div></td></tr></table></strong> <br>';
}

$html_encuesta.='<input type="submit" value="Votar">';
$html_encuesta.='</form>';
return 
$html_encuesta;
}
?>
en que falla?¿
  #2 (permalink)  
Antiguo 24/06/2007, 19:24
 
Fecha de Ingreso: febrero-2003
Ubicación: Santiago
Mensajes: 220
Antigüedad: 21 años, 2 meses
Puntos: 4
Re: No recuenta los votos

Borjimante

Podrias poner el error que te arroja el PHP, para saber en que falla? o simplemente no ingresa a alguna parte?

Saludos.
__________________
Roberto Osses Elgueta
Senior Web Developer
  #3 (permalink)  
Antiguo 24/06/2007, 19:53
Avatar de Bellenger  
Fecha de Ingreso: noviembre-2004
Ubicación: En un lugar del Mundo...
Mensajes: 599
Antigüedad: 19 años, 5 meses
Puntos: 4
Re: No recuenta los votos

ummm..
error...
Código PHP:
$ssql=mysql_query('SELECT * FROM encuesta_blt WHERE id_encuesta="'.$id_ENCUESTA.'" and id_opcion="'.$KEY.'"')or die(mysql_error()); 
al parecer en esta linea esta el error deberia ser algo asi:
Código PHP:
$ssql=mysql_query(”SELECT FROM encuesta_blt WHERE id_encuesta=".$id_ENCUESTA."’ and id_opcion=".$KEY.")or die(mysql_error()); 
espero haberte ayudado
  #4 (permalink)  
Antiguo 25/06/2007, 05:46
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: No recuenta los votos

Bellenger he puesto el codigo que me has dicho y me da sintax error, el problema esque no me deja cojer mas de un voto y dice que siempre has votado cuando no es asi.
  #5 (permalink)  
Antiguo 26/06/2007, 04:46
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: No recuenta los votos

nadie sabe que puede pasar?¿
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:32.