Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/01/2010, 05:58
visona
 
Fecha de Ingreso: febrero-2008
Mensajes: 675
Antigüedad: 16 años, 3 meses
Puntos: 5
Respuesta: Actualizar un div

Buenas; he probado tu scrpit y me queda así
Código PHP:
<script type="text/javascript">
var 
tmp="";
 
setInterval(function actualiza()
{
    
ajax=nuevoAjax();
    
ajax.open("GET""consulta_comentario.php?var1="+var1+"var2="+var2); // En ajax_select_db debes hacer el SELECT al query
 
    
ajax.onreadystatechange=function() 
    {
        if (
ajax.readyState==4
        {
            
// Si el valor devuelto por AJAX no es el mismo que tenemos en TMP entonces lo muestra, si no, almacena el contenido en TMP para una siguiente revision cada X tiempo (X lo define el Setinterval... no disminuyas mucho el tiempo para no saturar la BD.
            
if(!(ajax.responseText==$tmp)
            {
                 
document.getElementById("mainContent").innerHTML ajax.responseText;
            } else {
                 
$tmp=ajax.responseText;
        }
    }
    
ajax.send(null)
,
1000);
</script> 
Luego he creado la pagina "consulta_comantario" y este es el codigo
Código PHP:
<?php require_once('../../Connections/deume.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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;
}
}

$colname_comentarios "-1";
if (isset(
$_GET['var1'])) {
  
$colname_comentarios $_GET['var1'];
}
mysql_select_db($database_deume$deume);
$query_comentarios sprintf("SELECT id_comentarios FROM comentarios WHERE id_comentarios = %s ORDER BY id_comentarios DESC"GetSQLValueString($colname_comentarios"int"));
$comentarios mysql_query($query_comentarios$deume) or die(mysql_error());
$row_comentarios mysql_fetch_assoc($comentarios);
$totalRows_comentarios mysql_num_rows($comentarios);
?>
<!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>Documento sin título</title>
</head>

<body>
<?php echo $row_comentarios['id_comentarios']; ?>
</body>
</html>
<?php
mysql_free_result
($comentarios);
?>
Pero no me actualiza el DIV "mainContent".
Pero tengo una duda... En la pagina "consulta_comentario" le he puesto que filtre por URL la variable "var1" lo que no se si esta bien echo así.
Un saludo

Última edición por visona; 30/01/2010 a las 06:18