如何使用codeigniter从数据库中使用下拉列表筛选记录

tjrkku2a  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(383)

我将尝试如何过滤记录从数据库下拉使用codeigniter。结果我的记录找不到了。
这是我的控制器

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

class Tim extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model('Tim_Model');
        $this->load->model('NewKaryawan_model');
        $this->base=$this->config->item('base_url');
    }
    public function index()
    {
        // memanggil method get semua perusahaan dari perusahaan model
        $timID = $this->input->post('tim_id');

        // memanggil method get semua perusahaan dari perusahaan model
        $x['data']=$this->Tim_Model->getAllTim();
        $x['dataa']=$this->NewKaryawan_model->getNamaKaryawan($timID);
        //$x['dataa']=$this->NewKaryawan_model->getRecords($anggotaTim);

         $this->load->view('Tim/tim_list',$x);
        //$this->load->view('Tim/tim_list');
    }

我的模型

<?php
if  (!defined('BASEPATH')) exit('No direct script access allowed');
class NewKaryawan_model extends CI_Model
{
    public $table = 'karyawan';
    public $id = 'kr_id';
    public $order = 'DESC';

    public function __construct()
    {

    $this->load->database();
    }

    public function getNamaKaryawan($timID)
    {

        $hasil1['b']=$this->db->query("SELECT karyawan.* FROM tim INNER JOIN karyawan ON tim.tim_id=karyawan.tim_id WHERE tim.tim_id='$timID'");

         return $hasil1['b'];

    }

这就是我的观点

<?php $this->load->view('templates/header_manajer');?>
            <div class="row" style="margin-bottom: 10px">
            <div class="col-md-4">
                <h2 style="margin-top:10px">Data Tim</h2>
            </div>
            <div class="col-md-4 text-right">
                <?php echo anchor(site_url('Tim/create'), 'Tambah', 'class="btn btn-primary"'); ?>
        </div>
        </div>
                <div class="panel-body">
                    <table class="table table-bordered table-striped" id="mytable">
                        <tr>
                            <td> ID</td>
                            <td><select class="form-control" placeholder="Pilih Tim" name="TimID" id="tim_id"><br>

                                <?php foreach ($data->result_array() as $i) {?>
                                <option value="<?php echo $i['tim_id'];?>"> <?php echo $i['tim_id'];?></option><?php }?>
                            </td>
                        </tr>

                          <tr>
                            <td> Anggota</td>
                            <?php if(count($dataa->result_array())): ?>

                            <?php

                            foreach($dataa->result_array() as $j):

                              $kr_nama=$j['kr_nama'];

                              //$tim_anggota=$i['tim_anggota'];
                            ?>

                            <td><?php echo $kr_nama;?></td>
                             <tr><td><?php endforeach;?>  </td></tr>
                        </tr>
                    <?php else:?>
                    <tr><td>No record founds!</td></tr>
                <?php endif;?>

                         <tr><td> Action</td><td><a href="<?php echo base_url()."index.php/Tim/getTimID/".$i['tim_id']; ?>" class="btn btn-default btn-sm">Ubah</a> | <a href="<?php echo base_url()."index.php/Tim/deleteTim/".$i['tim_id']; ?>" class="btn btn-default btn-sm">Hapus</a> </td> </tr>

                    </table>
                </div>
            </div>

<?php $this->load->view('templates/footer'); ?>

这是我的数据库在这里输入图像描述
当我们选择团队id时,我想显示成员名称。您能告诉我错误吗?谢谢:)

egdjgwm8

egdjgwm81#

如果在phpmyadmin中执行,查询是否有效?
在模型中,不返回结果。我想你应该这样做 return $hasil1['b']->result();

相关问题