Skip to main content

Menampilkan total & waktu pencarian

October 3, 2011 by zacksyah

zacksyah's picture

Gmn ya kalau mau Menampilkan total & waktu pencarian sperti di google?
mohon bantuannya donk
berikut file codeigniternya

<?php
    class Welcomee extends CI_Controller
    {
        function __construct(){
            parent::__construct();
 
            $this->load->model('m_welcome');
            $this->load->helper('html');
        }
 
        function index()
        {
            $data['tampilan']=$this->m_welcome->tampilan();
            $this->load->view('tampilan',$data);
        }
 
        function cari()
        {
            $data['tampilan']=$this->m_welcome->caridata();
 
            if($data['tampilan']==NULL)
            {
                echo "data tidak ada";
                echo anchor('welcomee','kembali');
 
            }  else {
                $this->load->view('tampilan',$data);
            }
        }
    }
?>

<?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();
        }
 
    }
?>

<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>
<?php foreach($tampilan as $row) : ?>
<tr>
<td><?php echo $row->id; ?></td>
<td><?php echo $row->nip; ?></td>
<td><?php echo $row->nama; ?></td>
<td><?php echo $row->ttl; ?></td>
<td><?php echo $row->almt; ?></td>
<td><?php echo $row->hp; ?></td>
</tr>
<?php endforeach; ?>
</table>
<br>
<form action="<?php echo site_url();?>/welcomee/cari" method=POST>
    <input type=text name=cari>
    <input type=submit value="cari">
    </input></form>
<a href="<?php echo site_url();?>/welcomee">Tampilkan Semua</a>

Tolong bantun donk bingung niy, thanks b4 :(

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

coba edit lagi

October 6, 2011 by zawaruddin, 1 day 15 hours ago
Comment: 9097

zawaruddin's picture

coba model yg sodara purand buat diedit lagi seperti ini

function total_pencarian()
{
             $this->db->like('nama',$this->input->POST('cari'););
$this->db->from('pegawai');
return $this->db->count_all_results();
}

Sudah di autoload

October 4, 2011 by zacksyah, 3 days 16 hours ago
Comment: 9094

zacksyah's picture

Sudah di autoload librariesnya.

Klo itu hanya menampilkan

October 3, 2011 by zacksyah, 4 days 50 min ago
Comment: 9088

zacksyah's picture

Klo itu hanya menampilkan waktunya, klo mau tampilkan total row nya bagaimana?

Model function

October 3, 2011 by purandi, 4 days 43 min ago
Comment: 9090

purandi's picture

Model

function total_pencarian()
{
            $this->db->like('nama',$this->input->POST('cari'););
            return $this->db->count_all_results('pegawai');
}

Controller

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);
            }
}

View
Total Pencarian <?php echo $total_pencarian?>

Error bos gw dah sesuaikan

October 4, 2011 by zacksyah, 3 days 22 hours ago
Comment: 9092

zacksyah's picture

Error bos gw dah sesuaikan kode nya

A PHP Error was encountered
 
Severity: Notice
 
Message: Undefined variable: total_pencarian
 
Filename: views/tampilan.php
 
Line Number: 30

Trus pas gw ketikkan nama di field pencarian katanya
Fatal error: Call to undefined method CI_DB_mysql_driver::count_all_result() in C:\xampp\htdocs\ci\application\models\m_welcome.php on line 22

Itu gmn ya?

sudah kah anda mengload

October 4, 2011 by purandi, 3 days 21 hours ago
Comment: 9093

purandi's picture

sudah kah anda mengload database library di autload.php

Seharusnya ini tidak terjadi, soalnya tak tes di kompi saya aman

Sudah berhasil mas, tapi

October 4, 2011 by zacksyah, 3 days 15 hours ago
Comment: 9095

zacksyah's picture

Sudah berhasil mas, tapi datanya kan yg di cari ada satu, kenapa dia selalu menampilkan angka tujuh?

Di view tinggal di

October 3, 2011 by purandi, 4 days 4 hours ago
Comment: 9085

purandi's picture

Di view tinggal di tambahkan

Page rendered in <strong>{elapsed_time}</strong> seconds.

Premium Drupal Themes by Adaptivethemes