根据特定值显示数据库中的数据Codeigniter 3

问题描述 投票:0回答:1

我不知道如何解释这个,但我希望你能看到我的问题。我有kode_mtk的列表,如果我点击按钮输入它将直接查看接受该主题的学生列表。

enter image description here

我想基于kode_mtk和kelas显示该学生列表。我试图将$ kode_mtk和$ kelas放在模型和控制器中,但它不起作用。我希望你能指导我,因为我是codeigniter的新手。

这是我的控制器:

public function display(){
    $data['nama'] = $this->session->userdata('username');
    $kode_mtk = $this->input->post('kode_mtk');
    $kelas = $this->input->post('kelas');
    $data['hasil'] = $this->mtk_model->hasil();     

    $this->load->view('templates/header_tutor',$data);      
    $this->load->view('tutor/daftar_mtk_np', $data);
    $this->load->view('templates/footer_tutor');

}

这是我的模特:

function hasil () {

    $data = $this->session->userdata('username');
    $kode_mtk = $this->input->post('kode_mtk');
    $kelas = $this->input->post('kelas');
    $this->db->select('
        tb_kelas.idtutor,
        tb_kelas.nim,
        tb_kelas.nama,
        tb_kelas.masa,
        tb_kelas.kelas,
        tb_kelas.idtutorial,
        tb_mtk.kode_mtk,
        tb_mtk.kode_program_studi,
        prodi.nama_program_studi

    ');
    $this->db->from('tb_kelas');
    $this->db->join('tb_mtk', 'tb_mtk.idtutorial = tb_kelas.idtutorial');       
    $this->db->join('prodi', 'prodi.kode_program_studi = tb_mtk.kode_program_studi');
    $this->db->where('tb_kelas.idtutor',$data);
    $this->db->where('tb_kelas.masa',20172);
    $this->db->where('tb_mtk.kode_mtk',$kode_mtk);
    $this->db->where('tb_kelas.kelas',$kelas);      

    $query = $this->db->get();
    return $query->result();

}

这是我的看法

<div class="box-body table-responsive no-padding">
	<div class="form-group">
	  <table class="table table-hover">
		<tr>  
			<th>No</th> 
			<th>NIM</th>  
			<th>NAMA</th>					 
			<th>KELAS</th>
			<th>KODE MTK</th>
			<th>PRODI</th>
			<th>N.AKHIR</th>
			<th>AKSI</th>
		</tr>
		<?php  
		   if(isset($hasil)>0){$i=1; foreach($hasil as $row)  {  
					?>  
				<tr>  
					<td><?php echo $i; ?></td>  
					<td><?php echo $row->nim; ?></td>
					<td><?php echo $row->nama; ?></td>
					<td><?php echo $row->kelas; ?></td>
					<td><?php echo $row->kode_mtk; ?></td>
					<td><?php echo $row->nama_program_studi; ?></td>
					<td><input type="text" class="form-control na" id="na<?php echo $i; ?>" name="na" readonly /></td>
					<td>Input Nilai<td>
					
				</tr>  
			<?php $i++;}}?> 
			</form>
	  </table>
	</div>	
	</div>	
database codeigniter routes parameter-passing codeigniter-3
1个回答
0
投票

所以,我发现了错误。我将$ this-> input-> post更改为$ this-> input-> get并将其放入模型中。所以在控制器中我只需加载$ data ['hasil'] = $ this-> mtk_model-> hasil();感谢您的评论全部:)

© www.soinside.com 2019 - 2024. All rights reserved.