Tema: insert php
Ver Mensaje Individual
  #9 (permalink)  
Antiguo 28/09/2010, 17:23
sandinosaso
 
Fecha de Ingreso: julio-2008
Mensajes: 208
Antigüedad: 15 años, 10 meses
Puntos: 5
Respuesta: insert php

Código:
function contador () { 
    global $tableposts, $id;
    $result = mysql_query("UPDATE $tableposts SET post_lecturas = post_lecturas+1 where id= '$id' ");//ESTO SUPONE id es un campo char si es int saca las comillas simples
    
    if (!$result){
         //Ocurrio un error
        return -1;
    }else{
        //Si no ocurrio error ya aprovecho y consulto el total actual
        $actualizar = mysql_query("SELECT post_lecturas FROM $tablepost WHERE id= '$id' ");
        $resultado = mysql_fetch_array  ( $actualizar);
        if ($resultado == false)
            return -1;
        return $resultado[0];
   }

}
Esta funcion actualiza y devuelve la cantidad de lecutras y en caso de que ocurra un error devuelve -1.

Saludos.