已删除现有表数据-来自-
$this->model->Listar()
-至发件人-
$this->model->Buscarme($_POST['dni'])
修复了表格布局,以便页面正确显示,记录显示在搜索表单下方。
已更新
view/cliente/cliente.php
。
尝试以下操作:
<h1 class="page-header">CRUD con el patrón MVC en PHP POO y PDO </h1>
<a class="btn btn-primary pull-right" href="?c=cliente& =agregar">Agregar</a>
<a class="btn btn-primary pull-right" href="?c=cliente&a=ardila">Ardila</a>
<a class="btn btn-primary pull-right" href="?c=cliente&a=mateus">Mateus</a>
<br><br><br>
<table>
<form action="?c=cliente&a=buscame" method="post" >
<input type="text" name="dni" id="dni"/>
<input type="submit" name="boton" id="boton"/>
</form>
</table>
<table class="table table-striped table-hover" id="tabla">
<thead>
<tr>
<th style="width:180px; background-color: #5DACCD; color:#fff">ID</th>
<th style="width:120px; background-color: #5DACCD; color:#fff">DNI</th>
<th style="width:180px; background-color: #5DACCD; color:#fff">Nombre</th>
<th style=" background-color: #5DACCD; color:#fff">Apellido</th>
<th style=" background-color: #5DACCD; color:#fff">Correo</th>
<th style="width:120px; background-color: #5DACCD; color:#fff">Telefono</th>
</tr>
</thead>
<tbody>
<?php
$this->model->Buscarme($_POST['dni']);
$resultado = $this->model->resultado;
//print_r($resultado);
?>
<?php foreach($resultado as $r): ?>
<tr>
<td><?php echo $r['id']; ?></td>
<td><?php echo $r['dni']; ?></td>
<td><?php echo $r['Nombre']; ?></td>
<td><?php echo $r['Apellido']; ?></td>
<td><?php echo $r['Correo']; ?></td>
<td><?php echo $r['Telefono']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
<script src="assets/js/datatable.js">
</script>
</html>
我们将返回数据存储在函数变量而不是类变量中。修复了它。另外,计数器变量$i没有递增,使其每次重复递增1。
model/cliente.php
更新的功能:
public function Buscarme($dni){
try {
$stm = $this->pdo->prepare("SELECT * FROM cliente WHERE dni = :dni");
$stm->bindParam(':dni', $dni, PDO::PARAM_INT);
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
$this->resultado = array();
$i = 0;
foreach($res as $row){
$this->resultado[$i]['id'] = $row['id'];
$this->resultado[$i]['dni'] = $row['dni'];
$this->resultado[$i]['Nombre'] = $row['Nombre'] ;
$this->resultado[$i]['Apellido'] = $row['Apellido'];
$this->resultado[$i]['Correo'] = $row['Correo'] ;
$this->resultado[$i]['Telefono'] = $row['Telefono'] ;
$i++;
}
} catch (Exception $ex) {
die($e->getMessage());
}
}