Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing php pages without using the browser's refresh button 1

Status
Not open for further replies.

GAstrada

Programmer
Sep 20, 2000
97
Hello all !!

I have a mysql database table that dinamically has new records every minute. With sprintf() I've constructed a link to "record" one field named h6 with now() when the client click in the link (inclouded into the screen table).
Then, and knowing that header(location... doesen't work if any echo is sent to the client, I used at the end of the code, a Javascript code to redirect to a simple html file (h6.html) that all it does is <META HTTP-EQUIV="REFRESH" CONTENT="1;URL=h6.php"> with all the correct sintax. So, h6.php (the code I'm sending), shoud refresh in 1 second.

It's like a ping-pong: h6.html after 1 second is redirected to h6.php, which, in turn, after 10 seconds is again redirected to h6.html, and so. graboh6.php only update the h6 field in the table, (if the link is pressed) no output elsewhere.

Surprisingly, the only thing that update every 11 seconds
is an output of date(), in h6.php, so the script WORKS (there is a sleep(10) ) in the script, but nothing more is in the output on the screen. A BLACK SCREEN WITH ONLY THE DATE UPDATED!!!!

All this scripts works into the same window of a frameset.

And now....: if I CUT the Javascript redirection, all the scripts, output to the screen, and links asociated WORK FINE,... but need the client to use the Window's refresh button.

Any help will be appreciated. Thanks to all.
Regards.

Code:
<html>

<head>
  <title>Registrar H6</title>
</head>

<body bgcolor="#003333" text="#FFFF00" alink="#FF0000" vlink="#FF0000">

<?php

ini_set("max_execution_time",100000);        // hago un "override" de los "defaults" de PHP.INI
ini_set("pfpro.defaulttimeout",100000);      // y los llevo a varias horas. (se mide en segundos, eran 30!!!)
set_time_limit(100000);                      // timeout a varias horas ( argumento en segundos )

//$db = mysql_connect("localhost", "frtaxi", "fr%taxi")
$db = mysql_connect("localhost", "root")      // Intento asignar un "handle" (en version de produccion: CONTROLAR
                                              // los "paths" y otras cosas en  PHP.INI (Apache) )
or die ("No pude conectarme al servidor");    // y en DocumentRoot en HTTPD.CONF en .......\Apache\conf\

mysql_select_db("historico", $db)                // Lo selecciono
or die("No puedo acceder a la base de datos");

//$sresult = mysql_query("select * from diario where h6='0000-00-00 00:00:00'",$db);

//if (!$myrow=mysql_fetch_array($sresult))
//{
//@header("Location:h6.html");   // no hay nada para procesar
//}

// si no esta inicializado "cmd" a "postear" a h6.php
if(!isset($cmd))
{
   echo date('Y-m-d h:i:s');
   $sresult = mysql_query("SELECT * FROM diario WHERE h6='0000-00-00 00:00:00' ORDER BY diahora ASC",$db);
   echo "<table border = 6>\n";
   echo "<tr><th>TELEFONO</th><th>CELULAR</th><th>CALLE</th><th>NUMERO</th><th>OBSERVACIONES</th><th>DIA</th><th>MOVIL</th><th>TIEMPO</th><th>H6</th></tr>\n";

   while($myrow=mysql_fetch_array($sresult))
   {
      $movil=$myrow["movil"];
      $diahora=$myrow["diahora"];
      $horaunix=strtotime($diahora);  // evitamos problemas de "espacios" al armar la URL con campos datetime

      $h6=sprintf("<a href=graboh6.php?cmd=registrar&movil=%s&horaunix=%s>Registrar H6</a>", $movil, $horaunix);

      printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
      $myrow["telef"],
      $myrow["cellphone"],            // PRINTF() y SPRINTF() son funciones a estudiar en profundidad !!!!
      $myrow["calle"],
      $myrow["numero"],
      $myrow["observ"],
      $myrow["diahora"],
      $myrow["movil"],
      $myrow["codtiemp"],
      $h6);

//      hacer un link con el movil
//      echo "<a href='graboh6.php?cmd=registrar&movil=$movil'>Registrar H6</a>";

    }
    echo "</table>\n";
}
mysql_free_result($sresult);                   // LIBERAMOS memoria
mysql_close($db);
sleep(10);

echo "<script type='text/javascript'>";
echo "window.location='h6.html'";
echo "</script>";

?>

</body>

</html>
 
scrap the redirects.

use meta-refresh if you really must but even better is to retrieve only the required updated content through the use of AJAX (XHR) interaction with your php server.
 
Thanks jpadie !!! I'll try your methods..
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top