CodeIgniter Forums
Show total search - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Show total search (/thread-45764.html)



Show total search - El Forum - 10-05-2011

[eluser]zacksyah[/eluser]
This is my code & still have show total all data. I just want to display total data which i found.
Code:
<?php
    class Welcomee extends CI_Controller
    {
        function __construct(){
            parent::__construct();
        
            $this->load->model('m_welcome');
            $this->load->helper('html');
        }
        
        function index()
        {
            $data['total_pencarian']="";
            $data['tampilan']=$this->m_welcome->tampilan();
            $this->load->view('tampilan',$data);
        }
        
        function cari()
        {
            $data['tampilan']=$this->m_welcome->caridata();
            $data['total_pencarian']=$this->m_welcome->total_pencarian();
            
            if($data['tampilan']==NULL)
            {
                echo "data tidak ada";
                echo anchor('welcomee','kembali');
                
            }  else {
                $this->load->view('tampilan',$data);
            }
        }
    }
?>

Code:
<?php
    class M_welcome extends CI_Model
    {
        function tampilan()
        {
           //$this->db->from('pegawai');
           $query=$this->db->get('pegawai');
           return $query->result();
        }
        
        function caridata()
        {
            $c=$this->input->POST('cari');
            $this->db->like('nama',$c);
            $query=$this->db->get('pegawai');
            return $query->result();
        }
        
        function total_pencarian()
        {
            $this->db->like('nama',  $this->input->POST('cari'));
            return $this->db->count_all('pegawai');
        }
        
    }
?>

Code:
<center>
<h3>Tabel data mahasiswa<h3>


<table border=1 >
<tr>
<td>ID</td>
<td>NIM</td>
<td>NAMA</td>
<td>TTL</td>
<td>ALAMAT</td>
<td>HP</td>
</tr>
&lt;?php foreach($tampilan as $row) : ?&gt;
<tr>
<td>&lt;?php echo $row->id; ?&gt;</td>
<td>&lt;?php echo $row->nip; ?&gt;</td>
<td>&lt;?php echo $row->nama; ?&gt;</td>
<td>&lt;?php echo $row->ttl; ?&gt;</td>
<td>&lt;?php echo $row->almt; ?&gt;</td>
<td>&lt;?php echo $row->hp; ?&gt;</td>
</tr>
&lt;?php endforeach; ?&gt;
</table>
<br>
&lt;form action="&lt;?php echo site_url();?&gt;/welcomee/cari" method=POST&gt;
    &lt;input type=text name=cari&gt;
    &lt;input type=submit value="cari"&gt;
    &lt;/input&gt;&lt;/form>
Total Pencarian &lt;?php echo $total_pencarian?&gt;
<a href="&lt;?php echo site_url();?&gt;/welcomee">Tampilkan Semua</a>

Please help me, thanks b4