Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/08/2011, 15:11
Avatar de Jall251
Jall251
 
Fecha de Ingreso: marzo-2008
Mensajes: 7
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Sistema de votaciones a prueba de trolls.

oie disculpa me intereso tu comentario y me gustaria saber si me podrias ayudar un poco me gustaria lo mismo pero en php

tengo un script algo asi lo pongo
Código PHP:
<?

// iniciamos session
session_start ();

$dbConn mysql_connect("localhost""root""");
mysql_select_db("db"$dbConn);

//obtengo el id de la noticia
$notid $_GET['idNoticia'];
//selecciono la db y ago una query para saber los datos
$sql "SELECT * FROM votos WHERE noticia = '".$_GET['idNoticia']."'";
$resultado mysql_query($sql$dbConn) or die(mysql_error());
$query2 mysql_fetch_array($resultado);

//condiciono si existe la noticia y si no creo un nuevo voto con referencia a la noticia
if($query2['noticia'] != $notid){
mysql_query("INSERT INTO votos (noticia) VALUES ('$notid')"$dbConn);
}

//obtendo el id de la noticia para agregarlo e incrementar en la db referente a la noticia seleccionada
if($bueno=$_GET['b']){
    
//
    
$sql "SELECT * FROM votos WHERE noticia = '".$_GET['b']."'";
    
$resultado mysql_query($sql$dbConn) or die(mysql_error());
    
$query2 mysql_fetch_array($resultado);

$incremento $query2['bueno']+1;
mysql_query("UPDATE votos SET bueno = '$incremento' WHERE noticia = '".$_GET['b']."'");
//retorno a la noticia seleccionada
    
header'Location: voto.php?idNoticia='.$_GET['b']);
    die;
}

if(
$bueno=$_GET['m']){
    
//
    
$sql "SELECT * FROM votos WHERE noticia = '".$_GET['m']."'";
    
$resultado mysql_query($sql$dbConn) or die(mysql_error());
    
$query2 mysql_fetch_array($resultado);

$incrementoMalo $query2['malo']+1;
mysql_query("UPDATE votos SET malo = '$incrementoMalo' WHERE noticia = '".$_GET['m']."'");
//retorno a la noticia seleccionada
    
header'Location: voto.php?idNoticia='.$_GET['m']);
    die;
}


?>


Código HTML:
<p>&nbsp;</p>
<table width="400" border="1" align="center">
  <tr>
    <td colspan="3" ><center>
      Noticia: <?= $notid ?>
    </center></td>
  </tr>
  <tr>
    <td width="101">Total de Votos:</td>
    <td colspan="2"><?= $total = $query2['bueno'] + $query2['malo']; ?></td>
  </tr>
  <tr>
    <td>Buenos</td>
    <td width="38"><?= $query2['bueno'] ?></td>
    <td width="239"><a href="voto.php?b=<?=$_GET['idNoticia']; ?>"><img src="bien.png" width="35" height="25" border="0" /></a></td>
  </tr>
  <tr>
    <td>Malos</td>
    <td><?= $query2['malo'] ?></td>
    <td><a href="voto.php?m=<?=$_GET['idNoticia']; ?>"><img src="mal.png" width="35" height="25" border="0"/></a></td>
  </tr>
</table>
<p>&nbsp;</p> 
Todo el codigo lo he puesto junto en un solo archivo llamado voto.php

y la sql asi
Código:
CREATE TABLE `votos` (
  `id` int(10) NOT NULL auto_increment,
  `bueno` int(10) NOT NULL default '0',
  `malo` int(10) NOT NULL default '0',
  `noticia` int(10) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
Espero que me puedas ayudar un poco lo agradeceria mucho.