如何使用codeigniter

时间:2018-06-08 14:30:47

标签: php codeigniter

我已经从查询中获取结果,将它们显示在一个表格上,如下所示。 显示所有员工的表格 table that shows all employees

然后我可以进行搜索查询以获取我正在寻找的特定员工: 搜索名称结果 search for name result 问题是我如何选择或选择结果以在表格或表格中显示该信息,或者我可以用来将这些结果传递给其他输入的任何内容。

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h2>Busqueda de empleados</h2>
    <form action="" method="post" id="myform1">
        ver todos los empleados:
        <input type="text" name="buscar">
        <input type="submit" name="enviar1" id="enviar1" value="enviar">
        <hr>
    </form>

            <table class="table table-bordered table-responsive">
     <thead>
      <tr class= "info" bgcolor='#B9EDFD'>
        <th >INTERNO</th>
        <th>CURP</th>
        <th>NOMBRE</th>
        <th>A_PATERNO</th>
        <th>A_MATERNO</th>
     </thead>
      <tbody>
      <?php
        foreach ($empleados-> result() as $row) {
          echo "<tr>";
                echo "<td bgcolor='#EAECEE'>".$row->Interno;"</td>";
                echo "<td bgcolor='#EAECEE'>".$row->Curp;"</td>";
                  echo "<td bgcolor='#EAECEE'>".$row->Nombre;"</td>";
                  echo "<td bgcolor='#EAECEE'>".$row->A_Paterno;"</td>";
                  echo "<td bgcolor='#EAECEE'>".$row->A_Materno;"</td>";

                  "</tr>";
        }
      ?>
    </tbody>
</table>

</body>
</html>`

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Empleados extends CI_Controller {

     public function __construct() {
    parent::__construct();

    // Load the todo model to make it available 
    // to *all* of the controller's actions 
    $this->load->model('consultas_M');
  }


    public function busqueda(){
        if ($_POST) {
          $buscar = $this->input->post('buscar');

            } else {
                $buscar = '';
        }
        $data['empleados'] = $this->consultas_M->muestra($buscar);
    // 3. Render the view:
    $this->load->view('main/busqueda', $data);
    }   
}`

型号:

function __construct() {
    parent::__construct();
    $this->load->database();
  } 

function muestra($bus)
{
  $this->db->like('interno', $bus);
  $this->db->or_like('Curp', $bus);
  $this->db->or_like('Nombre', $bus);
  $this->db->or_like('A_Paterno', $bus);
  $this->db->or_like('A_Materno', $bus);

   $q= $this->db ->get('empleados');
  if($q -> num_rows() >=0){
    return $q;
  }else{
    return false;
  }
  }

0 个答案:

没有答案