搜索结果显示在页面顶部

时间:2018-04-07 06:33:48

标签: php mysql search

我无法将搜索结果显示在页面上的搜索按钮下方。 我还没有找到一种方法来在视图的tbody中显示结果,而不试图调用模型中的方法来产生一些错误。

这是controller / clienteController.php

<?php
include_once 'model/cliente.php';
class clienteController{
private $model;
public function __CONSTRUCT(){
$this->model = new cliente();
}
public function Paginar(){
require_once 'view/header.php';
require_once 'view/cliente/cliente.php';
}

public function buscar(){
$cliente = new cliente();
if(isset($_POST['dni'])){
$cliente = $this->model->Buscarme($_POST['dni']);
}
require_once 'view/header.php';
require_once 'view/cliente/cliente.php';
}
}

这是model / cliente.php

  <?php
  class cliente
  {
  private $pdo;
  public $id;
  public $dni;
  public $Nombre;
  public $Apellido;  
  public $Correo;
  public $Telefono;
  public $res;
  public function __CONSTRUCT()
  {
  try
  {
  $this->pdo = conectar();     
  }
  catch(Exception $e)
  {
  die($e->getMessage());
  }
  }
  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);
  foreach($res as $row){
  echo  $row['id'] . '</br>';
  echo  $row['dni'] . '</br>';
  echo  $row['Nombre'] . '</br>';
  echo  $row['Apellido'] . '</br>';
  echo  $row['Correo'] . '</br>';
  echo  $row['Telefono'] . '</br>';
  } 
  } catch (Exception $ex) {
  die($e->getMessage());
  }
  }
  }

将数据发送到此视图/ 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 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>            
        <th style="width:60px; background-color: #5DACCD; color:#fff"></th>
        <th style="width:60px; background-color: #5DACCD; color:#fff"></th>
    </tr>
</thead>
<tbody>
<?php foreach($this->model->Listar() 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>
        <td>
        </td>
    </tr>
<?php endforeach; ?>
</tbody>
</table> 
<form action="?c=cliente&a=buscame" method="post" >
<input type="text" name="dni" id="dni"/>
<input type="submit" name="boton" id="boton"/>
</form>
</tbody>
</body>
<script  src="assets/js/datatable.js">  
</script>
</html>

0 个答案:

没有答案