Codeigniter Example
Codeigniter Example
Screen shot
Screen shot
Controller

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

class User extends CI_Controller {

public function __construct() {
parent::__construct();
$this->load->database();
$this->load->model('user_model');
}

public function index()
{
$data['user']=$this->user_model->fetch_data();
$this->load->view('display',$data);
}

public function view_record()
{
$data['view_detail'] = $this->user_model->detailrecord();
$this->load->view('view_record', $data);
}

}

Model

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

class User_Model extends CI_Model {

public function fetch_data()
{
$this->db->select('*');
$q = $this->db->get('tbl_user');
return $q->result();
}

public function detailrecord() {
$id=$this->uri->segment(3);
$q = $this->db->get_where('tbl_user',array('id'=>$id));
return $q->row();

}

}

View

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<html>
<head>
<title>Display Data</title>
</head>
<body>
<table border="1">
<tr>
<td><b>Name</b></td>
<td><b>Email</b></td>
<td><b>View</b></td>
</tr>
<?php
foreach($user as $row){
?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->email; ?></td>
<td><a href="user/view_record/<?php echo $row->id; ?>">View</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>