Codeigniter pagination is not appeared - php

i have view vkategorimaterial like this
<table border="1">
<tr>
<td colspan="4">Tampilkan<?php
echo form_open('c_kategorimaterial/cari');
echo nbs();$intext=array('name' => 'cari', 'class' => 'GUI');
echo form_input($intext);
echo nbs(); $inbutton=array('value' => 'Cari', 'class' => 'button');
echo form_submit($inbutton);
echo form_close();
?></td>
</tr>
<tr>
<td colspan="4"><img class ="create" src="<?php echo base_url();?>img/create.png"></td>
</tr>
<tr>
<td>Nomor</td>
<td>Kode Kategori Material / Jasa</td>
<td>Nama Material / Jasa</td>
<td>Perintah</td>
</tr>
<?php if ( !empty($rows) )
{
$no = 1;
foreach ($rows as $row) { ?>
<tr id="row">
<td><?php echo $no;?></td>
<td><?php echo $row->Kode_Kategori_Material_Jasa;?></td>
<td><?php echo $row->Nama_Material_Jasa;?></td>
<td> <img class="perintah" src="<?php echo base_url(); ?>img/update.png"><img class="perintah" src="<?php echo base_url(); ?>img/delete.png"></td>
</tr>
<?php
$no++;
}
}
else { ?>
<tr id="row">
<td colspan="6" align="center">Tabel Kosong</td>
</tr>
<?php
}
?>
</table>
<?php echo $this->pagination->create_links(); ?>
then i made the controller named c_kategorimaterial here is the index part
function index()
{
$query = $this->m_kategorimaterial->get();
$config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['rows'] = $query->result();
$data['title'] = 'QB Kategori Material';
$this->load->view('menu',$data);
$this->load->view('v/vkategorimaterial');
}
i want to make a pagination that showing 5 rows per page. and here is the model of m_kategorimaterial->get
$this->db->order_by('Kode_Kategori_Material_Jasa','DESC');
$query = $this->db->get('ms_kategori_material',5);
return $query;
why does the pagination is not showing ? here is the result of print_r($data['rows']);
Array ( [0] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ006 [Nama_Material_Jasa] => Biji ) [1] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ004 [Nama_Material_Jasa] => Teneh ) [2] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ001 [Nama_Material_Jasa] => Air ) )

Try this block
function index()
{
$query = $this->m_kategorimaterial->get();
$config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 5;
$data['rows'] = $query->result();
$this->pagination->initialize($config);
$this->load->vars($data); // !!!
$data['title'] = 'QB Kategori Material';
$this->load->view('menu',$data);
$this->load->view('v/vkategorimaterial');
}
And in your view try this,
echo $this->pagination->create_links();

echo $this->pagination->create_links();

Include pagination library in controller
$this->load->library('pagination');
And alter a line in your controller to
$this->load->view('v/vkategorimaterial',$data);
Here is helpful link for you Codeigniter Pagination:

Related

Table content does not showing correctly

I have an issue to show a content that not showing correctly:
my NAME is showing over and over again
my IKLAN (image) too
but my SIZE is not showing over and over again
so funny
like this the eror
This is my View:
data.php
<thead>
<tr>
<?php $i = 1;?>
<th>Nomer</th>
<th>Nama</th>
<th>Iklan</th>
<th>Ukuran</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$no = $this->uri->segment('3') + 1;
foreach ($list as $l) {?>
<td align="center"><h4><?php echo $i++; ?></h4></td>
<td align="center"><h4><span style="font-weight:bold"><?php echo $l->nama_client?></span></h4></td>
<td align="center"><h4><img src="./upload_iklan/<?php echo $l->iklan;?>" id="gambar_nodin" width="200"/></h4></td>
<td align="center"><h3><?php echo $l->size_ads?></h3></td>
this is my controller : Iklan.php
public function __construct()
{
parent::__construct();
$this->load->model('iklan_model');
$this->load->helper(array('form','url'));
$this->load->library('form_validation','upload','pagination');
$this->load->helper('url');
}
public function dashboard()
{
$data['konten'] = "dashboard";
$this->load->view('index', $data);
}
public function index($offset=0)
{
$this->load->database();
$data['list']=$this->iklan_model->show_iklan();
json_encode($data);
$this->load->library('pagination');
$config['base_url'] = base_url();
$config['total_rows'] = $data;
$config['per_page'] = 10;
$from = $this->uri->segment(3);
$this->pagination->initialize($config);
$data['list'] = $this->iklan_model->data($config['per_page'],$from);
$this->load->view('data',$data);
}
this is my model:
Iklan_model.php
public function __construct()
{
parent::__construct();
}
function data($number,$offset){
return $query = $this->db->get('client,size,advertisement',$number,$offset)->result();
}
function jumlah_data(){
return $this->db->get('data')->num_rows();
}
Loop must be start before tag so it will print each row with proper data.
<?php
$no = $this->uri->segment('3') + 1;
foreach ($list as $l) {?>
<tr>
<td align="center"><h4><?php echo $i++; ?></h4></td>
<td align="center"><h4><span style="font-weight:bold"><?php echo $l->nama_client?></span></h4></td>
<td align="center"><h4><img src="./upload_iklan/<?php echo $l->iklan;?>" id="gambar_nodin" width="200"/></h4></td>
<td align="center"><h3><?php echo $l->size_ads?></h3></td>
</tr>
<?php } ?>

CodeIgniter Pagination : Show Records from SQL Server

In codeigniter, I use sqlsrv and pagination library to show records from database,
but after i click on page 2 on pagination link, the Records will show at the end of current page instead of showing in new page, any help would be greatly appreciated,
here is the Controller:
public function example1() {
$config = array();
$config["base_url"] = base_url() . "index.php/posts/example1";
$config["total_rows"] = $this->PostModels->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$config["num_links"] = 5;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->PostModels->
fetchdata($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("example1", $data);
Here is the Model:
public function record_count() {
return $this->db->count_all("BlawBlaw");
}
public function fetchdata($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get("BlawBlaw");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
& here is the View:
<table>
<tr>
<th><strong>Post Id</strong></th>
<th><strong>Post Title</strong></th>
<th><strong>Post Title</strong></th>
<th><strong>Post Title</strong></th>
</tr>
<?php foreach($results as $data){?>
<tr>
<td><?php echo $data->a;?></td>
<td><?php echo $data->b;?></td>
<td><?php echo $data->c;?></td>
<td><?php echo $data->d;?></td>
</tr>
<?php }?>
<p><?php echo $links; ?></p>
</table>
you can used this this model and view changes make in your code
Here is the Model:
function fetch_data($limit, $id)
{
$this->db->select('*')->from('category ')->limit($limit, $id);
//$this->db->limit($limit);
//$this->db->where('Cid', $id);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
return false;
& here is the View:
<table>
<tr>
<th><strong>Post Id</strong></th>
<th><strong>Post Title</strong></th>
<th><strong>Post Title</strong></th>
<th><strong>Post Title</strong></th>
</tr>
<?php foreach($results as $data){?>
<tr>
<td><?php echo $data->a;?></td>
<td><?php echo $data->b;?></td>
<td><?php echo $data->c;?></td>
<td><?php echo $data->d;?></td>
</tr>
<?php }?>
<p><?php foreach ($links as $link) {
echo $link; ?></p>
</table>

Pagination links not working

I am trying to show my table in pagination.Links are coming but when i click on a 2 or 3 or anything it goes to /view_expenses/view&per_page= this. and i ll get a 404 error.why its not showing the rest data?
This is my controller
class View_expenses extends CI_Controller
{
public function __construct()
{
parent::__construct();
$data['title']= 'View Expenses';
$this->load->view('header_view',$data);
$this->load->model('emp_expenses_model');
$this->load->library('form_validation');
$this->load->helper('url');
$this->load->library('pagination');
}
public function index()
{
}
function view($offset=0){
$limit=5;
//$this->uri->segment(3);
$this->load->model('emp_expenses_model');
//$result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
$result['countRows']=$this->emp_expenses_model->countRows();
$this->load->library('pagination');
$this->load->library('table');
$config=array(
'base_url' =>site_url ('/view_expenses/view'),
'total_rows' => $result['countRows'],
'per_page' => $limit,
'uri_segment' => 3,
'num_links' => 1,
);
//var_dump($config);
$this->db->limit(5);
$this->pagination->initialize($config);
$this->load->model('emp_expenses_model');
$this->data['view_expenses'] = $this->emp_expenses_model->get_all();
//$this->data['pagination'] = $this->pagination->create_links();
//var_dump($this->data['pagination']);die("jk");
$this->data['title'] = 'Payroll System';
$this->data['message'] = $this->session->flashdata('message');
$this->load->library('pagination');
$this->load->view('view_expenses', $this->data);
/*$this->load->view('add_list', $this->data);*/
}
This is my model
function getRows($limit,$offset)
{
$query=$this->db->select('expenses_id,id,dropdown,modeofpayment,amount')
->from('emp_expenses')
->limit($limit,$offset);
$result=$query->get()->result_array();
return $result;
//var_dump($result);
}
function countRows()
{
//$query="select count(*) as count from emp_expenses";
$result = $this->db->count_all_results('emp_expenses');
//$result=$this->db->query($query);
return $result;
//var_dump('countRows');
}
This is My View
<table cellspacing="0" cellpadding="2" border="0" id="tbl" style="width:100%">
<tr style="background-color:#045c97">
<?php echo $this->pagination->create_links()?>
<td class="heading">Employee ID</td>
<td class="heading">Drop Down</td>
<td class="heading">Mode OF Payment</td>
<td class="heading">Amount</td>
<td class="heading">Edit</td>
<td class="heading">Delete</td>
</tr>
<?php
foreach ($view_expenses as $m){
$list_id = $m['id'];
//print_r($list_id);die('adad');
//$m['username']='';
?>
<tr style="text-align:center;">
<td><?php echo $m['id'] ?></td>
<td><?php echo $m['dropdown'] ?></td>
<td><?php echo $m['modeofpayment'] ?></td>
<td><?php echo $m['amount'] ?></td>
<td>Edit</td>
<td>
<?php
echo anchor('view_expenses/delete_expenses/'.$list_id, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
?>
</td>
you need to use ? not & to separate a query string from the rest of request
Your query is written completely wrong, you must put a question mark before everything else in the URL.
foo://example.com:8042/over/there?name=ferret&color=brown#nose
\_/ \______________/\_________/ \______________________/ \__/
| | | | |
scheme authority path query fragment
Notice, the "Question-Mark", or query operator must come before any queries, but if there are more than one they should be seperated by the "&".
Try this:
/view_expenses/view?per_page=
As to the links not showing you what you want, your code is not correct in any way. Here is a tutorial in which I found easy to understand:
http://www.phpfreaks.com/tutorial/basic-pagination

Pagination in codeigniter 404 error

Controller file : function index here
public function index()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('register_model');
$this->load->library("pagination");
$config = array();
$config["base_url"] = base_url()."register";
$config["total_rows"] = $this->register_model->record_count();
$config["per_page"] = 5;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["result"] = $this->register_model->fetch_logs($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('register',$data);
}
here s my model functions
public function view()
{
$query = $this->db->query("select * from user_login");
return $query->result_array();
}
public function record_count()
{
return $this->db->count_all("user_login");
}
public function fetch_logs($limit, $start)
{
$this->db->limit($limit, $start);
$query = $this->db->get("user_login");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
here s my view codes
<form method="post" accept-charset="utf-8" action="<?php echo base_url(); ?>/register/create" class="myform" id="myform" />
<div style="text-align:left;"><h1>User Registration</h1></div>
<table width="488" border="0">
<tr>
<td colspan="3">User
<input name="user_name" type="text" size="40" /></td>
</tr>
<tr>
<td colspan="3">Pass
<input name="password" type="password" size="40" /></td>
</tr>
<tr>
<td width="278" align="right"><input name="submit" type="submit" value="ADD" class="big_btn"/></td>
<td width="148" align="center"> </td>
<td width="48" align="center"> </td>
</tr>
</table>
<p> </p>
<table width="679" border="1" cellpadding="3" cellspacing="0">
<tr><th width="202" align="center">User</th>
<th width="319" align="center">Password</th>
<th colspan="2" align="center">Action</th>
<?php
foreach ($result as $row)
{
?>
<tr>
<td height="32" align="center"><?php echo $row->user;?> </td>
<td align="center"><?php echo md5($row->pwd);?></td>
<td width="56" align="center"><a href="<?php echo base_url();?>/register/delete/<?php echo $row->id;?>">
<input name="delete" type="button" id="delete" value="x" class="del_btn">
</a></td>
<td width="68" align="center"><?php
$atts = array(
'width' => '700',
'height' => '300',
'scrollbars' => 'no',
'status' => 'no',
'resizable' => 'yes',
'screenx' => '600',
'screeny' => '150'
);
echo anchor_popup(base_url().'/register/viewmore/'.$row->id, '<input name="view" type="button" id="view" value="" class="view_btn">', $atts);
?></td>
</tr>
<?php
}
?>
</table>
</form>
</div> <p><?php echo $links; ?></p>
Here I can see the pagination links but after i clicks on links its giving 404 Page Not Found error
can any one check this and reply??
if your above controller is register controller then you can do
$config["base_url"] = site_url("register"); //this will call the index function of register contoller
Change this
$config["base_url"] = base_url()."register";
to this
$config["base_url"] = base_url('register'); // or you can use site_url('register');
public function index() {
$this->load->helper ( 'url' );
$this->load->helper ( 'form' );
$this->load->model ( 'register_model' );
$this->load->library ( "pagination" );
$config = array ();
$config ["base_url"] = base_url ( 'register/index/' );
$config ["total_rows"] = $this->register_model->record_count ();
$config ["per_page"] = 5;
$config ["uri_segment"] = 3;
$this->pagination->initialize ( $config );
$page = ($this->uri->segment ( 3 )) ? $this->uri->segment ( 3 ) : 0;
$data ["result"] = $this->register_model->fetch_logs ( $config ["per_page"], $page );
$data ["links"] = $this->pagination->create_links ();
$this->load->view ( 'register', $data );
}
I think here is the problem try this
like
$config['base_url'] = site_url('register/index/');

pagination not working unsolved error

hi everyone i am trying to build a pagination function in a web project i fallowed the user guide on codeigniter and a tutorial on net tuts here is the link http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-day-7-pagination/
but i keep getting these tow errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$pagination
Filename: views/result_view.php
Line Number: 41
and
Fatal error: Call to a member function create_links() on a non-object in C
cant figure these errors out where are they coming from and how can i fix them can some one help me here is my cmv :
controller
<?php
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->view('result_view', $data);
}
function pagination()
{
$this->load->library('pagination');
$config['base_url'] = 'result_controller/pagination';
$config['total_rows'] = $this->db->get('data')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
$this->load->view('result_view', $data);
}
view
<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 echo $this->pagination->create_links(); ?>
model
<?php
class Result_model extends CI_Model{
function result_getall(){
return $this->db->select('*')
->from('tblanswers, credentials')
->get()
->result_object();
}
}
?>
Remove this line from your view
<?php echo $this->pagination->create_links(); ?>
And paste this one
<?php echo $pagination ?>
EDIT
Instead of having a pagination function put the pagination code inside your getall() function like this:
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->library('pagination');
$config['base_url'] = 'result_controller/getall';
$config['total_rows'] = $this->db->get('data')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
$this->load->view('result_view', $data);
}
}

Categories