PHP - cuando escogo la fecha y le doy enviar no me muestra el gráfico

 
Vista:
sin imagen de perfil
Val: 135
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

cuando escogo la fecha y le doy enviar no me muestra el gráfico

Publicado por Rey (74 intervenciones) el 10/07/2020 04:43:57
consulta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Consulta MySQL- Tutorial 18</title>
</head>
<body>
<?php
 
$mysqli= new mysqli("localhost", "root", "", "tutorial17");
 
/* verificar la conexión */
if (mysqli_connect_errno()) {
    printf("Conexión fallida: %s\n", mysqli_connect_error());
    exit();
}
 
$resultado=$mysqli->query("SELECT DISTINCT `usuario` FROM `tabla` WHERE 1");
 
?>
 
 
<form action="respuesta.php" method="POST">
  <select name="usuario">
  <?php
    while ($row = $resultado->fetch_array())
      {
       echo "<option>";
        echo $row[0];
        echo "</option>";
      }
    mysqli_close($mysqli);
  ?>
  </select><br>
  <input type="date" name="fecha" ><br>
  <input type="submit" name="Enviar" >
</form>
</body>
</html>

respuesta.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
    <title>Respuesta MySQLL - Tutorial 18</title>
    <meta charset="UTF-8">
</head>
<body>
<?php
$mysqli= new mysqli("localhost", "root", "", "tutorial17");
 
/* verificar la conexión */
if (mysqli_connect_errno()) {
    printf("Conexión fallida: %s\n", mysqli_connect_error());
    exit();
}
 
 
function temperatura_diaria ($usuario,$ano,$mes,$dia) {
 
$resultado=$mysqli->query("SELECT UNIX_TIMESTAMP(fecha), mensaje FROM tabla WHERE year(`fecha`) = '$ano' AND month(`fecha`) = '$mes' AND day(`fecha`) = '$dia' AND `usuario`= '$usuario' AND `topic`= 'temperatura'");
while ($row = $resultado->fetch_array())
{
  echo "[";
  echo ($row[0]*1000)-10800000; //le resto 3 horas = 10800000 mill
  echo ",";
  echo $row[1];
  echo "],";
 }
}
?>
 
<div id="container1" style="width: 100%; height: 400px;"></div>
 
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
 
<script>
 
$(function () {
    $('#container1').highcharts({
        chart: {
            type: 'line',
            zoomType: 'x'
        },
        colors: ['#337ab7', '#cc3c1a'],
        title: {
            text: 'Temperatura'
        },
        xAxis: {
             type: 'datetime',
 
        },
        yAxis: {
            title: {
                text: 'Temperatura'
            }
        },
 
 
        series: [{
            name: 'Temp',
            data: [<?php
                $usuario = $_POST ['usuario'];
                $fecha = $_POST ['fecha'];
                $ano = substr("$fecha", 0, 4);
                $mes = substr("$fecha", 5, 2);
                $dia = substr("$fecha", 8, 2);
                temperatura_diaria($usuario, $ano , $mes, $dia);
                ?>
        ]},
 
    ],
    });
});
</script>
 
<?php
function tablaDeTopics ($usuario,$ano,$mes,$dia) {
 
    $resultado=$mysqli->query("SELECT fecha, topic, mensaje FROM tabla WHERE year(`fecha`) = '$ano' AND month(`fecha`) = '$mes' AND day(`fecha`) = '$dia' AND `usuario`= '$usuario' AND `topic`!= 'temperatura'");
 
    echo "<table border='1'>";
    echo "<tr>";
    echo "<td>";
    echo "Fecha";
    echo "</td>";
    echo "<td>";
    echo "Topic";
    echo "</td>";
    echo "<td>";
    echo "Mensaje";
    echo "</td>";
    echo "</tr>";
while ($row = $resultado->fetch_array())
    {
        echo "<tr>";
        echo "<td>";
        echo $row[0];
        echo "</td>";
        echo "<td>";
        echo $row[1];
        echo "</td>";
        echo "<td>";
        echo $row[2];
        echo "</td>";
        echo "</tr>";
    }
    echo "</table>";
    mysqli_close($mysqli);
}
tablaDeTopics($usuario, $ano , $mes, $dia)
?>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder