Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/04/2011, 07:15
santigl84
 
Fecha de Ingreso: abril-2011
Mensajes: 6
Antigüedad: 13 años
Puntos: 0
Pregunta Como restringir valoración por imagen y dia

Necesito restringir las valoraciones de las imagenes de mi pagina a una vez por imagen y dia.

tengo esta tabla:

Código PHP:
CREATE TABLE IF NOT EXISTS `ip_votos` (
  `
idint(3NOT NULL auto_increment,
  `
ipvarchar(16NOT NULL,
  `
id_imagenint(4NOT NULL,
  `
datevarchar(11NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=
y este es parte del codigo:


Código PHP:
<?php require("config.php");
  
  
//conecta con la base de datos
  
@mysql_connect($db_server,$db_user,$db_password) or die("No pudo conectarse con la base de datos del servidor. Compruebe las variables \$db_server, \$db_user y \$db_password en config.php");
  @
mysql_select_db($db_name) or die("La selección de la base de datos ha fallado. Compruebe la variable \$db_name en config.php");
 
  
//actualiza votos
  
$id $_POST["id"];
  
$vote $_POST["vote"];
  
//IP
  
$ip $_SERVER['REMOTE_ADDR'];
  
$fecha=date('d-m-Y');

  
//a partir de aqui es lo que he puesto para la Restriccion de IP
  
  
$sqls = @mysql_query("SELECT COUNT(*) FROM $db_ip_votos WHERE ip=$ip AND id_imagen={$_POST["id"]} AND date=$fecha");
  
$resultado=mysql_query($sqls) or die (mysql_error());
  
  if (
mysql_result($resultado,0) == 0){

  
//actualiza los votos en la base de datos
  
if(isset($id) && isset($vote)){
      @
mysql_query("UPDATE $db_table_pictures SET points=points+$vote,votes=votes+1 WHERE id=$id;");

  
//registra cada vez que votas una imagen la ip, el id de la imagen y la fecha
      
$sql = @mysql_query("INSERT INTO $db_ip_votos (ip,id_imagen,date) VALUES('$ip',{$_POST["id"]},'$fecha');");
  }
  
//restriccion de ip
  
} else {
   echo 
"Su ip: $ip ya havotado esta imagen, su voto no será válido";
  }

//Hasta aqui la actualizacion de los votos


 //store comment
  
$comment_name $_POST["comment_name"];
  
$comment_text $_POST["comment_text"];
  
  if(isset(
$comment_name) && isset($comment_text) && strlen($comment_name)>&& strlen($comment_text)>2){
    
$comment_name str_replace("<","&lt;",$comment_name);
    
$comment_name str_replace(">","&gt;",$comment_name);
    
$comment_name stripslashes($comment_name);

    
$comment_text str_replace("<","&lt;",$comment_text);
    
$comment_text str_replace(">","&gt;",$comment_text);
    
$comment_text stripslashes($comment_text);

    @
mysql_query("INSERT INTO $db_table_comments (id_pic,name,text,date) VALUES({$_POST["show"]},'$comment_name','$comment_text',".time().");");
  }
  
  
//image to be displayed
  
if(!isset($_GET["show"]) && !isset($_POST["show"])){
    
//random image
    
$ids = array();
    
$result = @mysql_query("SELECT id FROM $db_table_pictures;");
    list(
$min) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id ASC;"));
    list(
$max) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id DESC;"));
    
    while(list(
$ids[]) = @mysql_fetch_row($result));
    
    while(
true){
      
srand((double)microtime()*1000000);
      
      
$show rand($min,$max);
      
      if(
array_search($show,$ids)){
        break;
      }
    }
  }else{
    
//specific image
    
$show = isset($_GET["show"]) ? $_GET["show"] : $_POST["show"];
  }


  
$row = @mysql_fetch_array(@mysql_query("SELECT * FROM $db_table_pictures WHERE id=$show;"));
  list(
$next) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>$show ORDER BY id ASC LIMIT 0,1;"));

  
//calculate points
  
if($row["points"] != 0){
    
$row["points"] = number_format($row["points"]/$row["votes"],2,".","");
  }
  
  
//next image
  
if(!$next){
    list(
$next) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id ASC LIMIT 0,1;"));
  }
 
  
//print header
  
echo $header;
  
 
  
//print html
          
?><form action="vota.php" method="post">
            <table align="center" border="0" cellpadding="2" cellspacing="0">
              <tr>
                <td rowspan="2"><img src="imagenes/bad.png" width="50" height="50" /></td>
                <td rowspan="2" width="10">&nbsp;</td><?php

  
//voting form
  
for($i=1;$i<=$max_points;$i++){
                
?><td align="center"><?php echo $i?></td><?php
  
}

                
?><td rowspan="2" width="10">&nbsp;</td>
                <td rowspan="2"><img src="imagenes/good.png" width="50" height="50" /></td>
              </tr>
              <tr><?php

  
for($i=1;$i<=$max_points;$i++){
                
?><td align="center">
                
                <input type="radio" name="vote" value="<?php echo $i?>" onclick="submit();"></td><?php
  
}

              
?></tr>
            </table>
            <input name="show" type="hidden" value="<?php echo $next?>">
            <input name="id" type="hidden" value=" <?php echo $row["id"]; ?>">
          </form>
        </td>
      </tr>
      <tr>
        <td colspan="2" height="8">&nbsp;</td>
      </tr>
      <tr>
        <td align="center" colspan="2" height="<?php echo $img_height?>"><img alt="" border="0" src="<?php echo $img.$show.$img_format_info?>"></td>
      </tr>
      <tr>
        <td colspan="2" height="10">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" height="10">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" height="10">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top" width="50%">Imagen de <span class="resaltar"><?php echo $row["creator"]; ?>&nbsp;<?php echo $row["apellidos"]; ?></span><br><br>
        <span class="resaltar">Descripci&oacute;n de la Im&aacute;gen:</span><br /><br /><?php echo $row["comment"]; ?><br><br></td>
        <td align="right" valign="top" width="50%">Puntos: <span class="resaltar"><?php echo $row["points"]; ?></span> (<?php echo $row["votes"]; ?> votos)<br><br></td>
      </tr>
      <td colspan="2">
        <hr><?php

  $result 
= @mysql_query("SELECT * FROM $db_table_comments WHERE id_pic={$row["id"]} ORDER BY date DESC;");

  if(@
mysql_num_rows($result) == 0){
    
?>Sin comentarios<?php
  
}else{
    while(
$row = @mysql_fetch_array($result)){
        
?><span class="resaltar"><?php echo $row["name"]; ?></span> Escribe el <?php echo date("m/d/Y",$row["date"]); ?> a las <?php echo date("h:i a",$row["date"]); ?>:<br>
        <?php echo $row["text"]; ?>
        <br><br><?php
    
}
  }

        
?><hr>
        <b class="resaltar">Escribe un comentario:</b>
        <form action="vota.php" method="post">
          <table align="center" border="0" cellpadding="5" cellspacing="0">
            <tr>
              <td>Su nombre:</td>
              <td><input maxlength="50" name="comment_name" size="30" type="text"></td>
            </tr>
            <tr>
              <td valign="top">Comentario:</td>
              <td><textarea cols="70" name="comment_text" onkeyup="this.value=this.value.slice(0,<?php echo $comment_size?>);" rows="6"></textarea></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input type="submit" value="Enviar"></td>
            </tr>
          </table>
          <input name="show" type="hidden" value="<?php echo $show?>">
        </form><?php
  
  
//print footer
  
echo $footer;

  
//close database connection
  
@mysql_close();
?>
No se si estoy haciendo lo correcto ya que soy novato en php, si alguien me puede ayudar y decirme cual es el fallo o que codigo deberia poner se lo agradezco.

Muchas gracias