-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemaforo.php
149 lines (116 loc) · 4.91 KB
/
semaforo.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!-- PHP -->
<?php
class Record{
public $name;
public $surname;
public $level;
public $time;
public function __construct(){
$this->server = "localhost";
$this->user = "DBUSER2023"; // SI NO FUNCIONA PROBAR DBUSER2023
$this->pass = "DBPSWD2023"; // SI NO FUNCIONA PROBAR DBPSWD2023
$this->dbname = "records";
}
public function saveRecord() {
$db = new mysqli($this->server, $this->user, $this->pass, $this->dbname);
if ($db->connect_errno) {
$this->mensaje = "Error de conexión: " . $db->connect_error;
}
$sql = $db->prepare("INSERT INTO registro (nombre, apellidos, nivel, tiempo) VALUES (?,?,?,?);");
$sql->bind_param('sssi', $this->name, $this->surname, $this->level, $this->time);
$sql->execute();
$sql->close();
$db->close();
}
public function getRecords() {
$db = new mysqli($this->server, $this->user, $this->pass, $this->dbname);
if ($db->connect_errno) {
$this->mensaje = "Error de conexión: " . $db->connect_error;
}
$sql = $db->prepare("SELECT * FROM registro ORDER BY tiempo ASC LIMIT 10;");
$sql->execute();
$result = $sql->get_result();
if($result->num_rows > 0){
// Iniciar la tabla HTML
echo "<table border='1'>
<tr>
<th>Nombre</th>
<th>Apellidos</th>
<th>Nivel</th>
<th>Tiempo (s)</th>
</tr>";// Mostrar los datos en la tabla
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row['nombre'] . "</td>
<td>" . $row['apellidos'] . "</td>
<td>" . $row['nivel'] . "</td>
<td>" . ($row['tiempo']/1000) . "</td>
</tr>";
}
// Cerrar la tabla HTML
echo "</table>";
} else {
echo "No se encontraron registros.";
}
$sql->close();
$db->close();
}
}
?>
<!-- HTML -->
<!DOCTYPE HTML>
<html lang="es">
<head>
<!-- Datos que describen el documento -->
<meta charset="UTF-8" />
<title>F1 DESKTOP - SEMÁFORO</title>
<meta name="author" content="Ángel Macías"/>
<meta name="description" content="Juego de reacción de semáforo de F1: espera a que las luces se apaguen y presiona el botón para medir
tu tiempo de reacción. ¿Puedes mejorar tu tiempo y reaccionar como un piloto de Fórmula 1?"/>
<meta name="keywords" content="juego de reacción, semáforo F1, tiempo de reacción, luces de F1, botón de reacción, Fórmula 1, juego de reflejos, mejora de reflejos, semáforo, velocidad de reacción"/>
<meta name ="viewport" content ="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="estilo/estilo.css" />
<link rel="stylesheet" type="text/css" href="estilo/layout.css" />
<link rel="stylesheet" type="text/css" href="estilo/semaforo_grid.css" />
<link rel="icon" href="multimedia/juegos-favicon.ico" type="image/x-icon"/>
</head>
<body>
<!-- Datos con el contenidos que aparece en el navegador -->
<header>
<h1><a href="index.html">F1 Desktop</a></h1>
<nav>
<a href="index.html">Index</a>
<a href="piloto.html">Piloto</a>
<a href="noticias.html">Noticias</a>
<a href="calendario.html">Calendario</a>
<a href="meterologia.html">Meteorologia</a>
<a href="circuito.html">Circuito</a>
<a href="viajes.php">Viajes</a>
<a href="juegos.html" class="active">Juegos</a>
</nav>
</header>
<p>
Estás en <a href="index.html">Inicio</a> >> Juegos >> Semáforo
</p>
<nav>
<h2>Lista de Juegos</h2>
<a href="memoria.html">Memoria</a>
<a href="semaforo.php" class="active">Semáforo</a>
</nav>
<main>
</main>
<!-- PHP añadir al documento -->
<?php
$record = new Record();
if (count($_POST) > 0) {
$record->name = $_POST["name"];
$record->surname = $_POST["surname"];
$record->level = $_POST["level"];
$record->time = intval($_POST["time"]);
$record->saveRecord();
$record->getRecords();
}
?>
</body>
<script src="js/semaforo.js"></script>
</html>