why my pagination won't work?
Stuck for 24 hour just for this function. Am i wrong in the database query? I don't understand what's wrong with my code.
Here's the controller:
function search()
{
$category_type = $this->input->post('category_type');
$data['result'] = $this->Grabber_model->get_data($category_type);
$config = array();
$config['base_url'] = base_url() . "grabber/search/index/";
$config['total_rows'] = $this->Grabber_model->count();
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data["links"] = $this->pagination->create_links();
$this->load->view('global_h');
$this->load->view('grabber_view', $data);
$this->load->view('global_f');
}
Heres the model:
function get_data($category_type) {
$this->load->database();
$this->db->select('*');
$this->db->from('products');
$this->db->where('category_type', $category_type);
$this->db->order_by('create_at','desc');
$this->db->limit(50);
$query = $this->db->get();
return $query->result();
}
And this is the view:
<div class="center">
<?php foreach($result as $row){ ?>
<div style="margin:0 10px 10px 0;float:left;width:250px" class="img-thumbnail" >
<img data-original="http://static04-id.zalora.com<?php echo $row->image_full; ?>" width="240px" height="346px" class="lazy" /><br>
Brand: <?php echo $row->brand; ?><br>
SKU: <?php echo $row->sku; ?><br>
</div>
<?php } ?>
<div style="clear:both;text-align:center;"><?php echo $links; ?></div>
</div>
Hope you guys can solve my problem, thank you!
don't know pagination not working means what (Please explain more if you can) but as per my observation you have not added offset in $config array like
$config['offset'] = 'uri_segment or 0'
which you have to use in your query in limit method like
limit(50, $offset);
Related
i want to be able to access this variable on controller that i had make before
this is my code in my view
<tbody>
<?php foreach ($data->result() as $row):?>
<tr>
<td><?php echo $row->nama; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->password; ?></td>
<td>
Edit |
DELETE |
</td>
</tr>
<?php endforeach; ?>
</tbody>
i put some method that contain that variable on controller name Login, but i set my default controller as News. And i want to access that variable from Login Controller.
and this is my Login Controller
public function index()
{
$this->$data['login'] = $this->Login_Model->get_news();
$this->$data['title']= 'Data Pendaftaran';
// konfigurasi pagination//
$config['base_url'] = site_url('Login/index');
$config['total_rows'] = $this->db->count_all('anggota');
$config['per_page'] =4;
$config["uri_segment"] =3;
$choice = $config["total_rows"]/ $config["per_page"];
$config["num_links"] =floor($choice);
// style pagination untuk bootstrap v4//
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class = "pagination justify-content-center">';
$config['full_tag_close'] = '</ul></nav></div>';
$config['num_tag_open'] ='<li class="page-item"><span class ="page-link">';
$config['num_tag_close'] ='</span></li>';
$config['cur_tag_open'] ='<li class="page-item active"><span class="page-link">';
$config['cur_tag_close'] ='<span class="sr-only">(current)</span></span></li>';
$config['next_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['next_tagl_close'] ='<span aria-hidden="true">»</span></span></li>';
$config['prev_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['prev_tagl_close'] ='</span>Next</li>';
$config['first_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['first_tagl_close'] = '</span></li>';
$config['last_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['last_tagl_close'] ='</span></li>';
$this->pagination->initialize($config);
$data['page']=($this->uri->segment(3))? $this->uri->segment(3) : 0;
$data['data'] = $this->Login_Model->get_data_list($config["per_page"],$data['page']);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('anggotapendaftaran',$data);
}
im sorry for my bad language
You can do it in the following way:
On Controller, after you all code where you load view:
$data = array();
$data['title'] = 'Data Pendaftaran';
$this->load->view("yourviewname_view", $data);
on View, when you want to get title, you can get it like $data
example:
echo $data; //will give you "Data Pendaftaran"
If it's array, you can access it like:
echo $data['arrayKey'];
or
echo $data['pagination'];
I hope this will help
I have set the pagination to the page. but it doesn't recognize the variable that represent the pagination link from the controller. How can I solve it?
This is View "member_list.php"
<table class="table table-hover table-striped table-bordered">
<tr>
<th class="text-center">ID</th>
<th class="text-center">Name</th>
<th class="text-center">Number</th>
<th class="text-center">Type</th>
<th class="text-center">Unit</th>
<th class="text-center">Date</th>
<th class="text-center">Action</th>
</tr>
<tr>
<td class="text-center"><?php echo $member->ID; ?></td>
<td><?php echo $member->Name; ?></td>
<td><?php echo $member->Letter_Number; ?></td>
<td><?php echo $member->Letter_Type; ?></td>
<td><?php echo $member->Unit; ?></td>
<td><?php echo $member->Date; ?></td>
<tr>
<div class="pagination "><?php echo "<li>". $links."</li>";?></div> // it doesn't defined $links variable
Here is controller "Main.php"
class Main extends CI_Controller {
public function index ()
{
redirect('member_list');
}
public function pagination1() {
$this->load->model('members');
$this->load->library('pagination');
$config = array();
$config["base_url"] = base_url()."main/pagination1";
$config["num_links"]= $this->members->record_count();
$config["per_page"] = 5;
$config["total_rows"] = $this->members->record_count(); //method in controller
$config["use_page_numbers"] = TRUE;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["members"] = $this->members->fetch_data1($config["per_page"],$page);
$pa_links = $this->pagination->create_links();
$data["links"] = $this->pagination->create_links(); //explode(' ',$pa_links );
$data["u_connect"] = $user_connect;
$this->display('members_list',$data);
}
Here is model "members.php"
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Members extends CI_Model {
public function record_count() {
return $this->db->count_all("in_list");
}
public function fetch_data1($limit, $id) {
$this->db->limit($limit);
$this->db->where('id', $id);
$query = $this->db->get("in_list");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
I will just post one of mine and you can adapt it
public function index()
{
$config['base_url'] = base_url() . '/pages/index/';
$config['total_rows'] = $this->db->count_all_results('posts');
$config['per_page'] = 4;
$config['num_links'] = 4;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<div class='pagination'>";
$config['full_tag_close'] = "</div>";
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$parent = "main";
$this->db->select("title, content, date, last_date, slug")->where('parent', $parent)->where('status', 'publish')->order_by("id", "asc");
$query = $this->db->get('posts', $config['per_page'],$this->uri->segment(3));
if($query->result()){
$data["mainContent"] = $query->result();
}
$data['title'] = "title";
$data['main_content'] = 'pages/prime';
$this->load->view('pages/includes/template', $data);
}
You are using a model, but its little different than mine that doesnt use a model.
In your view, this is all you need AFTER your foreach
<?php echo $this->pagination->create_links();?>
try this
<p><?php echo $links;?></p>
insted of this line <div class="pagination "><?php echo "<li>". $links."</li>";?></div>
you can also set this configaration in your function
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
list page
<div class="container">
<!--search criteria-->
<div class="alert alert-info">
<form method="post" class="form-inline" action="<?php echo base_url();?>/admin/area/index" id="form_search">
<div class="pull-left" style="color:#666;">Show Results:
<select name="limit" id="limit" style="width:50px;">
<option value="10"<?php if(10==$limit_selected) echo "selected";?>>10</option>
<option value="20" <?php if(20==$limit_selected) echo "selected";?>>20</option>
<option value="30" <?php if(30==$limit_selected) echo "selected";?>>30</option>
<option value="40" <?php if(40==$limit_selected) echo "selected";?>>40</option>
<option value="50" <?php if(50==$limit_selected) echo "selected";?>>50</option>
</select>
</div>
<label style="color:#666;"> Search By City: </label>
<select id="cityId" name="cityId" >
<option value='0'> --All-- </option>
<?php
foreach($cityOptionList as $city) { ?>
<option value="<?php echo $city['id']?>" <?php if($city['id']==$cityId) echo "selected";?>><?php echo $city['name']?></option>
<?php } ?>
</select>
</form>
</div>
<!--search criteria end-->
<table class="table table-striped table-bordered bootstrap-datatable">
<thead>
<tr>
<th>Sl.no</th>
<th>Area Name</th>
<th>City</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach($areaList as $area) {?>
<tr>
<td><?php echo $i;?></td>
<td class="center"><?php echo $area->areaName;?></td>
<td class="center"><?php echo $area->city_name;?></td>
<td class="center">
<a href="<?php echo base_url();?>admin/area/edit/<?php echo $area->areaId ; ?>">
<i class="icon-edit" style="font-size:16px;"></i></a>
<!-- <a href="#" data-id="<?php echo $area->areaId;?>">
<i class="icon-trash" style="font-size:16px;"></i></a>-->
</td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
<?php echo $links;?>
</div>
<!--/container-->
<!--=== End Content Part ===-->
<script>
$(function() {
$("#cityId").change(function() {
$("#form_search").submit();
});
$("#limit").change(function() {
$("#form_search").submit();
});
/*
$(".pagination").click(function(){
alert("hi");
$("#form_search").submit();
})
*/
});
</script>
controller code
public function index(){
$searchParam = '';
if(! empty($this->input->get('q'))){
$searchParam = $this->input->get('q');
}
if(!empty($this->input->post('cityId'))){
$search_city= $this->input->post('cityId');
}
$data['title'] = 'Area';
$data['action'] = 'admin/area/';
$data['searchParam'] = $searchParam;
$data['arealist'] = $this->getList();
$this->load->view('admin/header',$data);
$this->load->view('admin/area/view.php', $data);
$this->load->view('admin/footer',$data);
}
protected function getList(){
$stateId = $this->session->userdata('stateId');
$searchParam = '';
$search_city = '';
if(! empty($this->input->get('q'))){
$searchParam = $this->input->get('q');
}
if(!empty($this->input->post('cityId'))){
$search_city= $this->input->post('cityId');
}
if(!empty($this->input->post('limit'))){
$limit= $this->input->post('limit');
}
else
{
$limit = 10;
}
$config = $this->config->item('pagination');
$config = array();
$config["base_url"] = base_url() . "admin/area/index/";
$config["total_rows"] = $this->area_model->getArea(0, 0, $searchParam, 1,$search_city);
$totalCount = $config['total_rows'];
$config["per_page"] = $limit;
$config["uri_segment"] = 4;
$config['use_page_numbers'] = TRUE;
$config['reuse_query_string'] = TRUE;
$data['cityId'] = $search_city;
$data['limit_selected'] = $limit;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 1;
$data["links"] = $this->pagination->create_links();
$data["areaList"] = $this->area_model->getArea($config["per_page"], $page, $searchParam,0,$search_city);
$data['cityOptionList'] = $this->area_model->getCityByStateId($stateId);
return $this->load->view('admin/area/list.php', $data, true);
}
in list page when i change the city then the data is getting according to city and displaying in list page and the pagination is displayed if there are more than selected records.
The problem is when i click on pagination link for searched values then all the records are loading instead of search values.
In pagination how to get the searched values only if the search is applied on the records.
Sorry missed your whole question. To incudle your search parameters as filters in paging you need to add them.Refer below link to see what setting in config you need to change.
https://www.codeigniter.com/userguide3/libraries/pagination.html#customizing-the-pagination
you need to change below setting.
$config[‘reuse_query_string’] = FALSE;
I'm guessing from your code that the search form will do a POST action when it gets submitted by the user. After the user submitted the form, of course it will work. Because they just did a POST request, and you fetch the search query from $_POST by using $this->input->post('user_input') or something similar. But then, when they try to navigate to another page by clicking on the page number link (which is a GET request), the search fails because the superglobal $_POST array is empty.
A solution to solve this problem is to set a session value (I recommend that you use CodeIgniter's Session Class) based on the user input and instead of using the search query from $_POST, and use the one stored in session instead.
try this change code with your requirment and your table
set controller this way
<?php
class pagination extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
$this->load->model('pagination_model');
}
public function index()
{
//pagination settings
$config['base_url'] = site_url('pagination/index');
$config['total_rows'] = $this->db->count_all('tbl_books');
$config['per_page'] = "3";
$config["uri_segment"] = 3;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = floor($choice);
// integrate bootstrap pagination
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
// get books list
$data['booklist'] = $this->pagination_model->get_books($config["per_page"], $data['page'], NULL);
$data['pagination'] = $this->pagination->create_links();
// load view
$this->load->view('pagination_view',$data);
}
function search()
{
// get search string
$search = ($this->input->post("book_name"))? $this->input->post("book_name") : "NIL";
$search = ($this->uri->segment(3)) ? $this->uri->segment(3) : $search;
// pagination settings
$config = array();
$config['base_url'] = site_url("pagination/search/$search");
$config['total_rows'] = $this->pagination_model->get_books_count($search);
$config['per_page'] = "5";
$config["uri_segment"] = 4;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = floor($choice);
// integrate bootstrap pagination
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = 'Prev';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
// get books list
$data['booklist'] = $this->pagination_model->get_books($config['per_page'], $data['page'], $search);
$data['pagination'] = $this->pagination->create_links();
//Load view
$this->load->view('pagination_view',$data);
}
}
?>
set model this way
<?php
class pagination_model extends CI_Model{
function __construct()
{
parent::__construct();
}
//fetch books
function get_books($limit, $start, $st = NULL)
{
if ($st == "NIL") $st = "";
$sql = "select * from tbl_books where name like '%$st%' limit " . $start . ", " . $limit;
$query = $this->db->query($sql);
return $query->result();
}
function get_books_count($st = NULL)
{
if ($st == "NIL") $st = "";
$sql = "select * from tbl_books where name like '%$st%'";
$query = $this->db->query($sql);
return $query->num_rows();
}
}
?>
then your veiw page looks like
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeIgniter Pagination Example with Search Query Filter</title>
<link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>">
<style type="text/css">
.bg-border {
border: 1px solid #ddd;
border-radius: 4px 4px;
padding: 15px 15px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2 well">
<?php
$attr = array("class" => "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1");
echo form_open("pagination/search", $attr);?>
<div class="form-group">
<div class="col-md-6">
<input class="form-control" id="book_name" name="book_name" placeholder="Search for Book Name..." type="text" value="<?php echo set_value('book_name'); ?>" />
</div>
<div class="col-md-6">
<input id="btn_search" name="btn_search" type="submit" class="btn btn-danger" value="Search" />
Show All
</div>
</div>
<?php echo form_close(); ?>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2 bg-border">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Book Name</th>
<th>Author Name</th>
<th>ISBN</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($booklist); ++$i) { ?>
<tr>
<td><?php echo ($page+$i+1); ?></td>
<td><?php echo $booklist[$i]->name; ?></td>
<td><?php echo $booklist[$i]->author; ?></td>
<td><?php echo $booklist[$i]->isbn; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<?php echo $pagination; ?>
</div>
</div>
</div>
</body>
</html>
I have a datatable with pagination and I have just added a search function. At the moment my search results do not have pagination. I have tried to add the configurations from my index to the search function but it hasn't worked. I'm wondering if I'm missing something. I'd appreciate it if someone can take a look at it?
Controller
public function index(){
$config['base_url'] = base_url('/Control/Users');
$config['total_rows'] = $this->UserModel->countUsers();
$config['per_page'] = 30;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="current"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['last_link'] = '>>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['datatable'] = $this->UserModel->getAllUsers($config["per_page"], $page);
$data['links'] = $this->pagination->create_links();
$data['counter'] = $config['total_rows'];
$data['message']='';
$this->load->view('control/controlMenu/navigationLink');
$this->load->view('control/controlUsers/manageUsers',$data);
$this->load->view('control/controlMenu/navigationJquery');
}
public function searchUser(){
$inputsearchterm = $this->input->post('inputsearchterm');
if($inputsearchterm!=""){
$data['datatable'] = $this->UserModel->searchUser($inputsearchterm);
$data['links'] = '';
$data['counter'] = $this->UserModel->countSearchUser($inputsearchterm);
$data['message']='';
$this->load->view('control/controlMenu/navigationLink');
$this->load->view('control/controlUsers/manageUsers',$data);
$this->load->view('control/controlMenu/navigationJquery');
}else{
redirect('Control/Users');
}
}
View
<?php echo form_open_multipart('Control/Users/searchUser','class="inputform"');?>
<div class="form-group">
<label for="inputsearchterm">Search</label>
<input type="text" class="form-control" id="inputsearchterm" name="inputsearchterm" placeholder="Search">
</div>
<button type="submit" class="btn btn-primary">Search</button>
<?php echo form_close(); ?>
<table class="table">
<thead>
<tr>
<td>Name</td>
<td>IC Number</td>
<td>Passport Number</td>
<td>Email</td>
<td>Phone</td>
</tr>
</thead>
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $dataitem):
$id = $dataitem->id;
?>
<tr>
<td class="name"><?php echo $dataitem->firstname." "; ?><?php echo $dataitem->lastname; ?></td>
<td class="icnumber"><?php echo $dataitem->icNumber; ?></td>
<td class="passportnumber"><?php echo $dataitem->passportNumber; ?></td>
<td class="email"><?php echo $dataitem->email; ?></td>
<td class="phone"><?php echo $dataitem->phone; ?></td>
<td><a class="edituser" href="<?php echo base_url();?>Control/UserDetail/<?php echo $id; ?>/<?php echo "true"; ?>"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>Edit</a></td>
<td><a class="deleteuser" href="<?php echo base_url();?>Control/Users/Users/deleteUser/<?php echo $id; ?>"><i class="fa fa-trash" aria-hidden="true"></i>Delete</a></td>
</tr>
<?php
endforeach;
}
?>
</tbody>
</table>
<p><?php echo $this->session->flashdata('Table'); ?></p>
<?php echo $links; ?>
<p><?php echo $this->session->flashdata('Form'); ?></p>
</div>
Model
public function searchUser($userdetail){
$this->db->select('*');
$this->db->from('Users');
$this->db->like('firstname',$userdetail);
$this->db->or_like('lastname',$userdetail);
$this->db->or_like('email',$userdetail);
$this->db->or_like('phone',$userdetail);
$this->db->or_like('icNumber',$userdetail);
$this->db->or_like('passportNumber',$userdetail);
$query = $this->db->get();
if($query->num_rows()>0){
return $query->result();
}else{
return $query->result();
}
}
public function countSearchUser($userdetail){
$this->db->select('*');
$this->db->from('Users');
$this->db->like('firstname',$userdetail);
$this->db->or_like('lastname',$userdetail);
$this->db->or_like('email',$userdetail);
$this->db->or_like('phone',$userdetail);
$this->db->or_like('icNumber',$userdetail);
$this->db->or_like('passportNumber',$userdetail);
$query = $this->db->count_all_results();
if($query>0){
return $query;
}else{
return 0;
}
}
i think you should add pagination library or check your active query in model
How can I make this code to list only the sales of the respective vendors? Currently it is displaying all orders.
It is not properly listing the data coming from the database, does not filter properly.
Controller:
function index(){
$this->gerenciar();}
function gerenciar(){
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/os/gerenciar/';
$config['total_rows'] = $this->os_model->count('os');
$config['per_page'] = 10;
$config['next_link'] = 'Próxima';
$config['prev_link'] = 'Anterior';
$config['full_tag_open'] = '<div class="pagination alternate"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li><a style="color: #2D335B"><b>';
$config['cur_tag_close'] = '</b></a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['first_link'] = 'Primeira';
$config['last_link'] = 'Última';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$this->pagination->initialize($config);
$this->data['results'] = $this->os_model->get('os','idOs,dataInicial,garantia,descricaoProduto,defeito,usuarios_id,status,observacoes,desconto,trocas','',$config['per_page'],$this->uri->segment(3));
$this->data['view'] = 'os/os';
$this->load->view('tema/topo',$this->data);
}
MODEL:
function get($table,$fields,$where='',$perpage=0,$start=0,$one=false,$array='array'){
$this->db->select($fields.',clientes.nomeCliente, clientes.tabelaPreco');
$this->db->from($table);
$this->db->join('clientes','clientes.idClientes = os.clientes_id');
$this->db->limit($perpage,$start);
$this->db->order_by('idOs','desc');
if($where){
$this->db->where($where);
}
$query = $this->db->get();
$result = !$one ? $query->result() : $query->row();
return $result;
}
VIEW:
<?php
foreach ($results as $r) {
if ($this->session->userdata('id') == $r->usuarios_id || $this->session->userdata('id') == '1') {
$dataInicial = date(('d/m/Y'),strtotime($r->dataInicial));
echo '<tr>';
echo '<td>'.$r->idOs.' -'.$r->usuarios_id.'</td>';
echo '<td>'.$r->nomeCliente.'</td>';
echo '<td>'.$dataInicial.'</td>';
echo '<td>'.$r->status.'</td>';
echo '<td>';
if($this->permission->checkPermission($this->session->userdata('permissao'),'vOs')){
echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/visualizar/'.$r->idOs.'" class="btn tip-top" title="Ver mais detalhes"><i class="icon-eye-open"></i></a>';
}
if($this->permission->checkPermission($this->session->userdata('permissao'),'eOs')){
echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/editar/'.$r->idOs.'" class="btn btn-info tip-top" title="Editar OS"><i class="icon-pencil icon-white"></i></a>';
}
if($this->permission->checkPermission($this->session->userdata('permissao'),'dOs')){
echo '<i class="icon-remove icon-white"></i> ';
}
echo '</td>';
echo '</tr>';
}
}?>
You are not filtering the records in your model. your $where is empty so the sql will return all the records.
you should get the vendor id from session or parameter and then pass it to your model with a where condition.