3
下午好! 我有一个与Php结合的HTML表。我想要做的是,当您向数据库中输入新数据时,表会刷新以显示新数据,但只显示表格而不显示页面的其余部分。老实说,我不是程序员,但我明白,它可以用JSON和Ajax完成,但不知道如何。如果有人有时间和耐心告诉我我多么感激。只刷新一张HTML表格,而不是整个页面
这是我的PHP代码:
<?php
// ----------- CONEXIÓN ------------------
require 'RecibeConsultaPuenteConexion.php';
//echo "Conexión OKAS <br />";
// ----------- TRAYENDO DATOS ------------------
$statement = $conexion->query('SELECT * FROM tbl_consultas');
$statement->execute();
$resultados = $statement->fetchAll();
foreach ($resultados as $fila) {
}
// json_encode($fila);
?>
,这是我的html代码:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
<table class="Pizarra" id="pizarra" name="pizarra" cellspacing="0px";>
<tr class="trThDos">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tbody>
<!-- Comienza PHP -->
<?php
$i = 0;
foreach ($resultados as $fila) {
?>
<tr class="trPizarra" id="trPizarra">
<td class="tdTurno" style="text-align:center;"><?php echo '#' . ++$i ?></td>
<td class="tdImg" style="text-align:center;"><?php echo $fila ['asunto'];
switch ($fila['asunto']){
case "0":
echo "<img src='./img/consulta-56-2.png' title=\"Consulta.\" height=\"32\" width=\"32\">";
break;
case "1":
echo "<img src='./img/shot-56-2.png' title=\"Inyección.\" height=\"32\" width=\"32\">";
break;
case "2":
echo "<img src='./img/ta-56-2.png' title=\"Toma de presión.\" height=\"32\" width=\"32\">";
break;
case "3":
echo "<img src='./img/cert-56-2.png' title=\"Certificado médico.\" height=\"32\" width=\"32\">";
break;
case "4":
echo "<img src='./img/consulta-56-4.png' title=\"Consulta ⬇ abajo.\" height=\"32\" width=\"32\">";
break;
case "5":
echo "<img src='./img/shot-56-4.png' title=\"Inyección ⬇ abajo.\" height=\"32\" width=\"32\">";
break;
case "6":
echo "<img src='./img/ta-56-4.png' title=\"Toma de presión ⬇ abajo.\" height=\"32\" width=\"32\">";
break;
case "7":
echo "<img src='./img/cert-56-4.png' title=\"Certificado médico ⬇ abajo.\" height=\"32\" width=\"32\">";
break;
default:
echo "Hubo un error en la selección de asunto";
break;
} ?></td>
<td class="tdNombre" id="tdNombre" style="text-align:center;"><?php echo $fila ['nombre_completo']; ?></td>
<td class="tdHr" style="text-align:center;"><?php echo $fila ['hora']; ?> <span class="icon icon-stopwatch"></span></td>
<td class="td-aceptar">
<a class="aceptar-a" id="aceptar-a" href="http://localhost/FARMAXIA/index.php?id=<?php echo $fila['ID']; ?>" title="Aceptar paciente." >
<button class="btn btn-xs" id="aceptar-btn" ><span class="glyphicon glyphicon-ok"></span> Aceptar</button>
</a>
</td>
</tr>
<?php } ?>
<!-- Terminó PHP -->
<tfoot class="tableFoot">
<tr>
<td colspan="5"><p> </p></td>
</tr>
</tfoot>
</tbody>
</table>
</form>
你用Ajax/JSON先试过了什么?如果没有,请查看它的快速教程,看看你是否可以自己实现它。 – Jhecht
你为什么不尝试使用jQuery数据表。它会自动照顾清爽和一切。 – Iftikhar