[eluser]ede196620[/eluser]
am working on a pagination for my website its first time i am trying to make this work the problem is that the pagination dose not turn pages when the number of the link is clicked. i very new to codeigniter and php and cant figure this out i tout this would be a great place to start to get some advice. Here is my code :
Controller
Code:
class Result_controller extends CI_Controller{
function page($page_num=1){
$results_per_page = 25;
$this->load->model('result_model');
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/Surva/index.php/result_controller/page/';
$config['total_rows'] = $this->result_model->count_all();
$config['per_page'] = $results_per_page;
$config['use_page_numbers'] = TRUE
$config['num_links'] = 10;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['records'] = $this->result_model->get_page($page_num, results_per_page);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('result_view', $data);
}
}
model
Code:
class Result_model extends CI_Model{
function get_page($page_num=1, $results_per_page=25) {
// Make sure we have a positive page number.
if ($page_num < 1)
{
$page_num = 1;;
}
$this->db->select('tblanswers.*,credentials.*');
$this->db->from('tblanswers');
$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'LEFT');
$this->db->limit(($page_num - 1) * $results_per_page, $results_per_page);
$query = $this->db->get();
return $query->result_array();
}
function count_all()
{
$this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'LEFT');
return $this->db->count_all('tblanswers);
}
}
and my view
Code:
<html>
<head>
<title>Results</title>
</head>
<body>
<center>
<div>
<table border="1">
<tr>
<th>Name</th>
<th>Second Name</th>
<th>Phone</th>
<th>Email</th>
<th>Answer</th>
<th>Comment</th>
</tr>
<?php foreach ($query as $row): ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->second_name; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
<td> <?php echo $row->answerA;?>
<?php echo $row->answerB;?>
<?php echo $row->answerC;?></td>
<td><?php echo $row->comment;?><br></td>
</tr>
<?php endforeach; ?>
</table>
<?php if (isset($pagination))
{
echo $pagination;
// echo "<pre>"; var_dump($query);
}
?>
</div>
</center>
<?php echo anchor('http://localhost/Surva/index.php/home', 'Home'); ?>
</body>
</html>