New question

Question:

Date: 28-10-2016 13:53:34 (In Spanish)

Problema al refrescar página[Resolved]

Hola gente...ando con un problema que ahora me di cuenta.... tengo un php que me levanta datos de un microcontrolador, me almacena datos cada 5 minutos, y promedia cada hora, el tema es que cuando refresco pantalla me carga 0.
la carga lo hace por parametro get, como puedo hacer para que el usuario que ingrese no me haga la llamada al get y solo cargue cuando envie le microcontrolador?
Como siempre GRACIAS
<?php

	//enlace a BD
		$enlace = mysqli_connect("127.0.0.1","root","", "sensores");
	
	if (!$enlace) {
		echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
		echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL;
		echo "error de depuración: " . mysqli_connect_error() . PHP_EOL;
		exit;
	}

	//echo "Éxito: Se realizó una conexión apropiada a MySQL! " . PHP_EOL;
	//echo "Información del host: " . mysqli_get_host_info($enlace) . PHP_EOL;

// Leemos los valores que nos llegan por GET
  $WindDirection = (isset($_GET["WindDirection"]) ? mysqli_real_escape_string($enlace, $_GET["WindDirection"]) : NULL);
  $WindSpeedAverage = (isset($_GET["WindSpeedAverage"]) ? mysqli_real_escape_string($enlace, $_GET["WindSpeedAverage"]) : NULL);
  $WindSpeedMax = (isset($_GET["WindSpeedMax"]) ? mysqli_real_escape_string($enlace, $_GET["WindSpeedMax"]) : NULL);
  $Temperature = (isset($_GET["Temperature"]) ? mysqli_real_escape_string($enlace, $_GET["Temperature"]) : NULL);
  $RainfallOneHour = (isset($_GET["RainfallOneHour"]) ? mysqli_real_escape_string($enlace, $_GET["RainfallOneHour"]) : NULL);
  $BarPressure = (isset($_GET["BarPressure"]) ? mysqli_real_escape_string($enlace, $_GET["BarPressure"]) : NULL);
  $Humidity = (isset($_GET["Humidity"]) ? mysqli_real_escape_string($enlace, $_GET["Humidity"]) : NULL);
  $time = time();
  $fecha= date("d-m-Y (H:i:s)", $time);
	
	
 //insertamos los datos en la tabla temporal
  	$query = "INSERT INTO temporal(WindDirection,WindSpeedAverage,WindSpeedMax,Temperature,RainfallOneHour,BarPressure,Humidity ) VALUES ('".$WindDirection."','".$WindSpeedAverage."','".$WindSpeedMax."','".$Temperature."','".$RainfallOneHour."','".$BarPressure."','".$Humidity."')";
  	mysqli_query($enlace, $query);
	
	//consulta el id 
 	$resultado = mysqli_query($enlace, "SELECT MAX(id) AS 'id' from temporal WHERE estado = 0");
    $fila = mysqli_fetch_assoc($resultado);
    $fila['id'];
	
     
  $res = mysqli_query($enlace, "select id,   WindDirection,WindSpeedAverage,WindSpeedMax,Temperature,RainfallOneHour,BarPressure,Humidity,estado, fecha from temporal order by id desc");
      while($i = mysqli_fetch_array($res)){
		  
		  echo $id= $i[0];
          echo " <br/> Direccion del viento : ".$WindDirection = $i[1]."  ";
		  echo " <br/> Velocidad del viento : ". $WindSpeedAverage = $i[2]."Km/h" ;
          echo " <br/> Velocidad max del viento : ".$WindSpeedMax = $i[3]."  ºC" ;        
		  echo " <br/> Temperatura : ".$Temperature = $i[4]."  ºC";
          echo " <br/> Lluvia : ".$RainfallOneHour = $i[5]."  mm/h"; 
          echo " <br/> Presion atmosferica : ".$BarPressure = $i[6]."  Pascales"; 
          echo " <br/> Humedad : ".$Humidity = $i[7]."  %";
           echo " <br/> Fecha y Hora : ".$fecha = $i[9]."";  
          break;
      }
	
	
	
	
	

	
   // Si es igual a 12 inserta los valores en valores
If ($fila['id'] == 12)  {
    
	$Direccion=0;
	$Velocidad=0;
	$Temperatura=0;
	$OneHour=0;
	$Presion=0;
	$Humedad=0;
  	
	$i = 1;
	
			 
	$resultado = mysqli_query($enlace,'SELECT * from temporal ');
      if(mysqli_num_rows($resultado)==12){
         while($i = mysqli_fetch_array( $resultado)){
             $Direccion = $Direccion + $i[0];
             $Velocidad =  $Velocidad + $i[1];
             $Temperatura = $Temperatura + $i[2];
             $OneHour = $OneHour + $i[3];
             $Presion = $Presion + $i[4];
             $Humedad = $Humedad + $i[5];
             }
		
             $Direccion = $Direccion /12;
             $Velocidad =  $Velocidad /12;
             $Temperatura = $Temperatura /12 ;
             $OneHour = $OneHour /12 ;
             $Presion = $Presion /12;
             $Humedad = $Humedad /12;
         
             $query = "INSERT INTO  valores (WindDirection,WindSpeedAverage,Temperature,RainfallOneHour,BarPressure,Humidity  ) VALUES ($Direccion, $Velocidad, $Temperatura, $OneHour, $Presion, $Humedad)";
          mysqli_query($enlace, $query);

             $query = "UPDATE temporal SET estado = 1";
		 
             mysqli_query($enlace, $query);
		     mysqli_query($enlace, "TRUNCATE TABLE temporal");
             mysqli_close($enlace);
    		 }
    
 }
	

	
?>
<!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="refresh"  content="60" />
<title>ESTACION METEOROLOGICA DEL CENS Nº 451 - MONTE HERMOSO</title>
</head>

<body>
<p>Estado del tiempo actualizado cada 5 minutos</p>

<p>
<table border="1" cellspacing=1 cellpadding=2 style="font-size: 8pt">
</p><tr> </tr>
<table width="946" border="1">
  <tr>
    <td width="276">&nbsp;</td>
    <td width="330">PROMEDIOS PRONOSTICO CADA 1 HORA</td>
    <td width="318">&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="" border="1" cellpadding=2 cellspacing=1 style="font-size: 10pt" align="center"><tr>
<td ><font face="verdana"><b>Id</b></font></td>
<td ><font face="verdana"><b>Dirección del viento</b></font></td>
<td  align="center" valign="middle"><font face="verdana"><b>Velocidad del viento</b></font></td>
<td ><font face="verdana"><b>Temperatura</b></font></td>
<td ><font face="verdana"><b>Lluvia</b></font></td>
<td ><font face="verdana"><b>Presion</b></font></td>
<td ><font face="verdana"><b>Humedad</b></font></td>
<td ><font face="verdana"><b>Fecha y Hora</b></font></td>
</tr>

<?php  
  //enlace a BD
    $enlace = mysqli_connect("127.0.0.1","root","", "sensores");

if (!$enlace) {
    echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
    echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL;
    echo "error de depuración: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

  $result = mysqli_query($enlace, "SELECT *  from valores ORDER BY fecha desc");
  $numero = 0;
  while($row = mysqli_fetch_array($result)){
    echo "<tr><td><font face=\"verdana\">" . 
	    $row["id"] . "</font></td>";
    echo "<td><font face=\"verdana\">" . 
	    $row["WindDirection"] . "</font></td>";
    echo "<td><font face=\"verdana\">" . 
	    $row["WindSpeedAverage"] . "</font></td>";
	echo "<td><font face=\"verdana\">" . 
	    $row["Temperature"] . "</font></td>";
	echo "<td><font face=\"verdana\">" . 
	    $row["RainfallOneHour"] . "</font></td>";
	echo "<td><font face=\"verdana\">" . 
	    $row["BarPressure"] . "</font></td>";
	echo "<td><font face=\"verdana\">" . 
	    $row["Humidity"] . "</font></td>";
    echo "<td><font face=\"verdana\">" . 
	    $row["fecha"]. "</font></td></tr>";    
    $numero++;
  }
  echo "<tr><td colspan=\"15\"><font face=\"verdana\"><b>Cantidad de Registros: " . $numero . 
      "</b></font></td></tr>";
  
  mysqli_free_result($result);
  mysqli_close($enlace);
?>
</table>
</body>
</html>
Tags: $_GET - MySQL - PHP - Question Votes: 2 - Answers: 1 - Views: 12 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

  • Date: 28-10-2016 17:49:53 me la respondo sola... la rta mas a la vista imposible...
    Hice un php aparte que solo cargue y el otro me levanta los listados.
      Votes: 3 - Link answer
     
To actively participate in the community first must authenticate, enter the system.Sign In
 
frjcbbae garagebible.com