Ver Mensaje Individual
  #29 (permalink)  
Antiguo 09/05/2008, 09:21
miSko
 
Fecha de Ingreso: septiembre-2005
Mensajes: 840
Antigüedad: 18 años, 7 meses
Puntos: 84
Re: Limite en un user

En mi Script, quitando la primera linea donde elimino los antiguos al dia de hoy, puede hacer exactamente lo mismo que el tuyo, osea contar quien borra mas, pk guardaria el numero de borrados de cada user para cada dia, y sin necesidad de tener 3 campos por dia y por usuario

1000 usuarios, 10 dias = 30000 a tu modo ( contando q todos eliminen 3 )
frente a los 10000 de mi metodo, logrando un 300% mas de velocidad a la hora de contar los registros debido a que hay un 66,67% menos de registros ;)


Cita:
Iniciado por farra Ver Mensaje
aca tenes un script con un contador y todo bien completito...

Tabla: controlborrar
campos: (UserID, Fecha)
----------
Tabla: registros
campos: (idregistro, titulo, texto)

Código PHP:
<?php require_once('Connections/testsite.php'); ?>
<?php
$USERID
="1"// reemplazar por la variable que trae el id puede ser de sesion..
$hoy=date("Y-m-d H:i:s");

// comando anti inyeccion sql que genera dreamweaver
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$hoyini=date("Y-m-d")." 00:00:00";
$hoyfin=date("Y-m-d")." 23:59:59";
mysql_select_db($database_testsite$testsite);
$query_contolborra "SELECT count(*) as total FROM controlborrar WHERE UserID = '$USERID' AND Fecha >= '$hoyini' AND Fecha <= '$hoyfin' ";
$contolborra mysql_query($query_contolborra$testsite) or die(mysql_error());
$row_contolborra mysql_fetch_assoc($contolborra);
$totalRows_contolborra mysql_num_rows($contolborra);
$borrar="";
if(
$row_contolborra['total'] < "3"){
$borrar="SI";
}else{
$borrar="NO";
}

mysql_free_result($contolborra);
if ((isset(
$_GET['idregistro'])) && ($_GET['idregistro'] != "")) {
if (
$borrar == "SI") {

 
// aca borra
  
$deleteSQL sprintf("DELETE FROM registros WHERE idregistro=%s",
                       
GetSQLValueString($_GET['idregistro'], "int"));

  
mysql_select_db($database_testsite$testsite);
  
$Result1 mysql_query($deleteSQL$testsite) or die(mysql_error());
  
  
// aca inserta quien borro y la fecha
  
$insertSQL sprintf("INSERT INTO controlborrar (UserID, Fecha) VALUES (%s, %s)",
                       
GetSQLValueString($USERID"int"),
                       
GetSQLValueString($hoy"date"));

  
mysql_select_db($database_testsite$testsite);
  
$Result2 mysql_query($insertSQL$testsite) or die(mysql_error());
  
$msg="";
}else{
 
$msg="?msg=Solo puedes borrar 3 registros por dia";
}  
// direcciona a index
  
$deleteGoTo "index.php".$msg;

  
header(sprintf("Location: %s"$deleteGoTo));
}


$USERID="1"// reemplazar por la variable que trae el id puede ser de sesion..
mysql_select_db($database_testsite$testsite);
$query_registros "SELECT idregistro, titulo, texto FROM registros";
$registros mysql_query($query_registros$testsite) or die(mysql_error());
$row_registros mysql_fetch_assoc($registros);
$totalRows_registros mysql_num_rows($registros);

$hoyini=date("Y-m-d")." 00:00:00";
$hoyfin=date("Y-m-d")." 23:59:59";
mysql_select_db($database_testsite$testsite);
$query_contolborra "SELECT count(*) as total FROM controlborrar WHERE UserID = '$USERID' AND Fecha >= '$hoyini' AND Fecha <= '$hoyfin' ";
$contolborra mysql_query($query_contolborra$testsite) or die(mysql_error());
$row_contolborra mysql_fetch_assoc($contolborra);
$totalRows_contolborra mysql_num_rows($contolborra);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Borraste hasta ahora: <strong><?php echo $row_contolborra['total']; ?></strong> registro<br /><br />
<?php if (($_GET['msg'] != "") && ($row_contolborra['total'] >= "3")){ ?>Acceso Denegado: <?php echo $_GET['msg']; ?><?php ?><br /><br />
<?php do { ?>
  <?php echo $row_registros['titulo']; ?> - <a href="index.php?idregistro=<?php echo $row_registros['idregistro']; ?>">Borrar</a><br />
  <?php } while ($row_registros mysql_fetch_assoc($registros)); ?>
</body>
</html>
<?php
mysql_free_result
($registros);
?>

hace casi lo mismo que lo que posteo misko.. con 1 diferencia...

este en ves de update hace insert... entonces podes llevar un registro de borrados anteriores de los usuarios incluso tener un top 10 de los mas borradores...

ejemplo: si mas adelante queres ver quien es el que todos los dias borra minimo 3...





PD: Pk se han Unido 2 Posts? :S:S:S