Menampilkan Data Di SQL Server ke Codeigniter

created by Sance ainul yaqin
email : isthebestleonardo@gmail.com




Models/siswa_model.php

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

class Siswa_model extends CI_Model {

public function tampil()
{
return $this->db->get('tb_Siswa');
}
}


Controller/welcome.php

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

class Welcome extends CI_Controller {

public function index()
{
$data['data']=$this->siswa_model->tampil()->result_object();
$this->load->view('welcome_message',$data);
}
}


Views/welcome_message.php

<body>

<div id="container">
<h1>Tampil data</h1>

<div id="body">
<table>
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Nim</th>
<th>Alamat</th>
</tr>
</thead>
<tbody>
<?php $no=1;foreach($data as $v):?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $v->nama;?></td>
<td><?php echo $v->nim;?></td>
<td><?php echo $v->alamat;?></td>
</tr>
<?php $no++; endforeach;?>
</tbody>
</table>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
<?php echo print_r($data)?>
</body>


Ket : Jika ingin menggunakan array maka sebagai berikut.
result_object()  diganti dengan result_array()

$v->nama;  diganti menjadi $v['nama'];
$->nim; diganti menjadi $v['nim'];
$->alamat; diganti menjadi $v['alamat'];






Menampilkan Data Di SQL Server ke Codeigniter Menampilkan Data Di SQL Server ke Codeigniter Reviewed by Leo on 09:11 Rating: 5

No comments