Welcome Guest, Not a member yet? Register   Sign In
how to display data to the view?
#6

[eluser]Thorpe Obazee[/eluser]
I suggest you just return the result from the model and pass it to the view

[quote author="yudahebat" date="1244032293"]I have a model like this
Code:
class Crud extends Model
{
    function Crud()
    {
        parent::Model();
    }
    
/* PILIH DATA */

    function cetak_data()
    {
        $this->db->query('SELECT tgl_pesan FROM reservasi WHERE tgl_pesan BETWEEN '. $this->input->post('dari_tgl').
        ' AND '.$this->input->post('sampai_tgl').'');
        $query = $this->db->get('reservasi');
        if ($query->num_rows() > 0)
        {
            return $query->result();
        }

        return FALSE;
    }
}

and controller like this

Code:
function cetak_data()
    {
        $data['css1']        = $this->css;
        $data['base']         = $this->base;
        $data['menu_adm']     = $this->menu;
        $data['myrobots']     = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | Cetak Data';
        $data['pesan'] = $this->Crud->cetak_data();

        $this->load->view('cetak_data',$data);  
    }

and my view like this
Code:
<h1 style="color:#E7541A;">Data User</h1>
        <table width="925" border="0" cellpadding="0" cellspacing="0" class="tabel" >
        <tr>
            <td width="60" class="tabel"><p>TANGGAL</p></td>
            <td width="90" class="tabel"><p>ID</p></td>
            <td width="80" class="tabel"><p>ID USER</p></td>
            <td width="150" class="tabel"><p>BIAYA TOTAL</p></td>
        </tr>
        &lt;?php foreach($pesan as $r): ?&gt;
        <tr>
            <td  class="tabel2" valign="top"><p>&lt;?= $r->id;?&gt;</p></td>
            <td  class="tabel2" valign="top"><p>&lt;?= $r->user_id;?&gt;</p></td>
            <td  class="tabel2" valign="top"><p>&lt;?= $r->user_id;?&gt;</p></td>
            <td  class="tabel2" valign="top"><p>&lt;?= $r->user_id;?&gt;</p></td>
            </tr>
        &lt;?php endforeach; ?&gt;
        </table>

but its didn't show the data
on $pesan just become array on the view not the data that ive choose...

what wrong? help please...[/quote]

look above. What you did is that you overwritten your $data variable over and over which gives you just one row.

Then you didn't loop through your array so you got 'Array' as an output.


Messages In This Thread
how to display data to the view? - by El Forum - 06-03-2009, 01:31 AM
how to display data to the view? - by El Forum - 06-03-2009, 01:37 AM
how to display data to the view? - by El Forum - 06-03-2009, 03:34 AM
how to display data to the view? - by El Forum - 06-03-2009, 03:35 AM
how to display data to the view? - by El Forum - 06-03-2009, 03:38 AM
how to display data to the view? - by El Forum - 06-03-2009, 03:42 AM
how to display data to the view? - by El Forum - 06-03-2009, 03:50 AM
how to display data to the view? - by El Forum - 06-03-2009, 08:05 AM
how to display data to the view? - by El Forum - 06-03-2009, 08:54 AM
how to display data to the view? - by El Forum - 06-03-2009, 09:05 AM
how to display data to the view? - by El Forum - 06-03-2009, 09:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB