i am getting error in my program. in this program i want to make if periode active show data when the periode active but when periode not active not show data anything. but i try this condition i am getting error Trying to get property of non-object in model.
this is modal
function get_id_periode_open()
{
$this->db->where('tgl_dari <= curdate()');
$this->db->where('tgl_sampai >= curdate()');
// $this->db->where('status', 'open');
$row = $this->db->get('periode')->row();
$id_periode = $row->id_periode; //line error
return $id_periode;
}
this is my controller
function index($nama = '',$period = 0,$geup = 0)
{
$this->load->model('mukt');
$id_periode = $this->mukt->get_id_periode_open();
$this->data['id_periode_sekarang'] = $id_periode;
if ($id_periode)
{
$this->data['ukt2'] = $this->mukt->get_ukt($perpage,$offset);
}
else
{
echo "string";
$this->data['contents'] = '<div class="twelve wide column">Tidak ada periode aktif</div>';
}
if (!$nama AND $this->input->post('nama'))
{
$nama = $this->input->post('nama');
}
else if(!$nama)
{
$nama = 0;
}
if ($this->input->post('id_periode')){
$period = $this->input->post('id_periode');
}
else if(!$period)
{
$period = 0;
}
if ($this->input->post('geup')){
$geup = $this->input->post('geup');
}
else if(!$geup)
{
$geup = 0;
}else{
$geup = urldecode($geup);
}
// echo $period. urldecode($geup). $nama;
$count = $this->mukt->get_count_peserta_ukt($period, urldecode($geup), $nama);
// print_r($count);
// exit;
// Set up pagination
$offset = 0;
$perpage = 1;
$uri_segment = 6;
if ($count > $perpage) {
$this->load->library('pagination');
$this->load->config('pagination');
$config = $this->config->item('pag');
$config['base_url'] = site_url('pelatih/ukt/'.$nama.'/'.$period.'/'.$geup);
$config['total_rows'] = $count;
$config['per_page'] = $perpage;
$config['uri_segment'] = $uri_segment;
$config['first_page'] = 'Awal';
$config['last_page'] = 'Akhir';
$config['next_page'] = '«';
$config['prev_page'] = '»';
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
if($this->uri->segment($uri_segment)){
$offset = $this->uri->segment($uri_segment);
}
}
else {
$this->data['pagination'] = '';
$offset = 0;
}
$this->data['periode'] = $this->mperiode->get_periode();
if ($period AND $geup)
{
$this->data['ukt2'] = $this->mukt->get_cari_peserta_ukt($period, $geup ,$nama,$perpage,$offset);
}
else if($nama && (!$period || !$this->input->post('geup')))
{
$this->data['ukt2'] = $this->mukt->get_cari_peserta_ukt("", "",$nama,$perpage,$offset);
}
else
{
$this->data['ukt2'] = $this->mukt->get_ukt($perpage,$offset);
}
$this->data['title'] ='UKM Taekwondo | ukt';
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('pelatih/ukt/view_ukt', $this->data, true);
$this->load->view('template/wrapper/pelatih/wrapper_anggota',$this->data);
please tell me how to solved this error.
thank you.
may be your query returns no result, so try doing:
$query = $this->db->get('periode');
if( $query->num_rows() > 0 ) {
$row = $query->row();
$id_periode = $row->id_periode;
return $id_periode;
}
return 0;
Related
Codeigniter pagination with the passing parameter to where clause links not working
Here is my Model
public function record_count($category) {
return $this->db->where('sub_category_name',$category)->count_all_results("categories_item");
}
public function fetch_departments($category,$limit, $start) {
$this->db->limit($limit, $start);
$query=$this->db->where('sub_category_name',$category)->get("categories_item");
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
return false;
}
//Here is Controller
public function categories_item()
{
$this->load->database();
$this->load->library('pagination');
$this->load->model('Home_model');
$config = array();
$config["base_url"] = base_url() . "Home/categories_item";
$category=$this->uri->segment(3);
$this->db->where('sub_category_name',$category);
$config['total_rows'] = $this->db->get('categories_item')->num_rows();
$config['use_page_numbers'] = TRUE;
$config["per_page"] = 1;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? ($this->uri->segment(3)) : 0;
$data["link"] = $this->pagination->create_links();
if( !$data["results"] = $this->Home_model->fetch_departments($category,$config["per_page"], $page))
{
error_reporting(1);
}
else
{
$this->load->view("category_item_list",$data);
}
}
Hi I need hel I'm trying to get pagination with search results.
I don't know what I am doing wrong. Because my results don't show up.
Here is my Model
function search_posts($query, $pagina, $por_pagina)
{
$this->db->select();
$this->db->from('posts');
$this->db->like("post_title", $query, 'both');
$this->db->or_like("post", $query, 'both');
$this->db->order_by('post_id', 'desc');
$this->db->limit($pagina, $por_pagina);
$query = $this->db->get();
return $query->result_array();
}
public function contar_filas()
{
$this->db->select();
$this->db->from('posts');
$query = $this->db->count_all_results();
return $query;
}
Here is my Controller
public function buscar()
{
$this->load->model('M_Articulos');
$data['posts'] = '';
$data['sin_resultados'] = '';
$query = trim($this->input->get('query', TRUE));
if (sizeof($query) == 0)
{
show_404();
}
if ($query)
{
if ($this->uri->segment(3))
{
$pagina = $this->uri_segment(3);
}
else
{
$pagina = 0;
}
$por_pagina = 4;
$data['posts'] = $this->M_Articulos->search_posts($query, $pagina, $por_pagina);
if ($data['posts'] != FALSE)
{
$data['posts'] = $this->M_Articulos->search_posts($query, $pagina, $por_pagina);
$config['base_url'] = base_url() . 'admin/buscar?query=' . $query;
$config['per_page'] = $por_pagina;
$config['total_rows'] = $this->M_Articulos->contar_filas();
$config['uri_segment'] = 3;
$config['enable_query_strings'] = TRUE;
$config['query_string_segment'] = 'page';
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
}
else
{
$data['sin_resultados'] = 'nada';
}
}
else
{
$data['sin_resultados'] = 'nada';
}
$this->load->view('admin/layouts/header');
$this->load->view('admin/modules/buscar', $data);
$this->load->view('admin/layouts/footer');
}
does anyone know how to make it work?
I'm going to be more specific. What i want is that when i search somethin in search page there is a pagination. Thanks
After searching data when i click on next page then it doesn't work with searching results. After click it goes on first page. How can i solve this problem ?
Thank you
Controller:
public function gkclientsadd(){
$arg["src"] = 0;
$arg["pageOffset"] = 0;
$np = $this->uri->segment(3);
$data["offset"] = 0;
$this->search_by = 0;
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
if(isset($_GET["client_search"]))
{
$arg["login"] = $this->input->get('login');
$arg["pwd"] = $this->input->get('pwd');
$arg["basetariff"] = $this->input->get("basetariff");
$arg["crc"] = $this->input->get("crc");
$arg["resone"] = $this->input->get("resone");
$arg["rpp"] = $this->default_rpp;
$arg["offset"] = $this->default_offset;
$arg["src"] = 1;
$this->search_basetariff = $arg["basetariff"];
$this->search_currency = $arg["crc"];
$this->search_parent = $arg["resone"];
$this->search_by = 1;
//print_r($arg);die;
} else $arg["src"] = 0;
}
if(!empty($np)){
$arg["pageOffset"] = ($np/$this->default_rpp);
$arg["rpp"] = $this->default_rpp;
$arg["offset"] = ($this->default_rpp)*$arg["pageOffset"];
$data["offset"] = $arg["offset"];
$arg["src"] = 1;
}
$data["gkclientsData"] = $this->admin_model->getGkclients($this->userId, $this->rtc_table,$arg, $this->default_rpp, $this->default_offset);
$data["getTotalGk"] = $this->admin_model->getTotalGk($this->rtc_table,$arg);
$data["totalRecords"] = count($data["getTotalGk"]);
$data["totalPage"] = $data["totalRecords"]/$this->default_rpp;
$data["Page"] = $arg["pageOffset"]+1;
$config = array();
$config["base_url"] = base_url() . "index.php/admin/gkclientsadd";
$config["total_rows"] = $data["totalRecords"] ;
$config["per_page"] = $this->default_rpp;
$config["uri_segment"] = 3;
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["links"] = $this->pagination->create_links();
$this->load->view('admin/clients/gkclientsadd',$data);
}
Model:
public function getGkclients($userId, $rtc_table,$arg, $default_rpp,$default_offset)
{
$this->load->database();
if($arg['src']== 1){
$whr = "";
$rpp = "";
$offset = "";
if(!empty($arg["rpp"])) $rpp .= " LIMIT ".$arg["rpp"]."";
if(!empty($arg["offset"])) $offset .= " OFFSET ".$arg["offset"]."";
if(!empty($arg["login"])) $whr .= " AND $rtc_table.login = '".$arg["login"]."'";
if(!empty($arg["pwd"])) $whr .= " AND $rtc_table.password = '".$arg["pwd"]."'";
if(!empty($arg["basetariff"])) $whr .= " AND $rtc_table.id_tariff = '".$arg["basetariff"]."'";
if(!empty($arg["crc"])) $whr .= " AND $rtc_table.id_currency = '".$arg["crc"]."'";
if(!empty($arg["resone"])) $whr .= " AND $rtc_table.id_res = '".$arg["resone"]."'";
} else {
$whr="";
$rpp= "Limit $default_rpp";
$offset= "OFFSET $default_offset";
}
$query = "SELECT DISTINCT $rtc_table.id_client,$rtc_table.id_res,$rtc_table.login,$rtc_table.password,$rtc_table.id_tariff,
$rtc_table.account_state,$rtc_table.type,$rtc_table.type2,currency_names.name
FROM $rtc_table, currency_names
WHERE currency_names.id = $rtc_table.id_currency $whr
order by $rtc_table.login ASC $rpp $offset";
$query_result = $this->db->query($query);
$gkData=$query_result->result();
return $gkData;
}
http://i.stack.imgur.com/yMa6d.jpg
I have pagination, and my pagination is working fine if I click next number.
View :
1 2 >
if I am clicking on 2 it goes on second page and shows proper result.but if I want to come back on 1 than its not redirect to page 1. here is my controller code:
public function index($date_start = 'all', $date_end = 'all', $title = 'all', $cid = 0, $skpd = 'all', $offset = NULL)
{
if($_POST)
{
$filter = array(
($this->input->post('filter_date_start') == '') ? 'all' : $this->input->post('filter_date_start'),
($this->input->post('filter_date_end') == '') ? 'all' : $this->input->post('filter_date_end'),
($this->input->post('filter_title') == '') ? 'all' : $this->input->post('filter_title'),
($this->input->post('filter_kategori') == 0) ? 0 : $this->input->post('filter_kategori'),
($this->input->post('filter_skpd') == '') ? 'all' : $this->input->post('filter_skpd')
);
$url = implode('/', $filter);
redirect('document/index'.$url);
}
//echo urldecode($title);
$this->load->model('News_model');
$this->load->library('pagination');
$data['title'] = 'Informasi Publik';
$param_document = array('status' => 1);
if(!empty($tid)) $param_document['tid'] = $tid;
if($date_start != 'all') $param_document['date_start'] = $date_start;
if($date_end != 'all') $param_document['date_end'] = $date_end;
if(!empty($cid)) $param_document['cid'] = $cid;
if($title != 'all') $param_document['title'] = urldecode($title);
if($skpd != 'all') $param_document['skpd'] = $skpd;
$params_total = $param_document;
$param_document_berkala = $param_document;
$param_document_serta_merta = $param_document;
$param_document_setiap_saat = $param_document;
$param_document_dikecualikan = $param_document;
$param_document['limit'] = 10;
$param_document['offset'] = $offset;
$data['document'] = $this->Document_model->get($param_document);
//dimodif cara urang
$data['bijilkategori'] = $this->Document_model->tampil();
// get document download count
foreach($data['document'] as $i => $row)
{
$document_transaction = $this->Document_model->get_transaction(array('did' => $row['document_id']));
$data['document'][$i]['download_count'] = empty($document_transaction) ? 0 : $document_transaction[0]['count'];
}
/*
$config['base_url'] = site_url('document/index/'.
(empty($tid) ? 0 : $tid).'/'.$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd
);
*/
$config['base_url'] = site_url('document/index/'.
$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd
);
$config['total_rows'] = count($this->Document_model->get($params_total));
$config['uri_segment'] = 9;
$this->pagination->initialize($config);
$data['main'] = 'document/document_indeks';
$data['kategori'] = $this->get_category();
$data['type'] = $this->get_type(TRUE);
$data['filter_kategori'] = $cid;
//dihidden ku urang
//$data['filter_type'] = $tid;
$data['filter_date_start'] = ($date_start == 'all') ? '' : $date_start;
$data['filter_date_end'] = ($date_end == 'all') ? '' : $date_end;
$data['filter_title'] = ($title == 'all') ? '' : $title;
$data['filter_author'] = ($skpd == 'all') ? '' : $skpd;
$param_document_berkala['tid'] = 1;
$param_document_serta_merta['tid'] = 2;
$param_document_setiap_saat['tid'] = 3;
$param_document_dikecualikan['tid'] = 4;
$data['total_record'] = count($this->Document_model->get($params_total));
$data['total_record_berkala'] = count($this->Document_model->get($param_document_berkala));
$data['total_record_serta_merta'] = count($this->Document_model->get($param_document_serta_merta));
$data['total_record_setiap_saat'] = count($this->Document_model->get($param_document_setiap_saat));
$data['total_record_dikecualikan'] = count($this->Document_model->get($param_document_dikecualikan));
$this->load->view('layout', $data);
}
Model:
public function get($params = array())
{
if(isset($params['fields']))
{
$this->db->select($params['fields']);
}
else
{
$this->db->select('*');
}
if(isset($params['id']))
{
$this->db->where('document.document_id', $params['id']);
}
elseif(isset($params['code']))
{
$this->db->where('document_code', $params['code']);
}
elseif(isset($params['date_start']) AND isset($params['date_end']))
{
$this->db->where('document_date >=', $params['date_start'].' 00:00:00');
$this->db->where('document_date <=', $params['date_end'].' 23:59:59');
}
elseif(isset($params['tid']))
{
$this->db->where('type_id', $params['tid']);
}
elseif(isset($params['cid']))
{
$this->db->where('document.category_id', $params['cid']);
}
elseif(isset($params['uid']))
{
$this->db->where('user_id', $params['uid']);
}
elseif(isset($params['sid']))
{
$this->db->where('document.skpd_id', $params['sid']);
}
if(isset($params['title']))
{
$this->db->like('document_title', $params['title']);
}
if(isset($params['author']))
{
$this->db->like('document_author', $params['author']);
}
elseif(isset($params['date']))
{
$this->db->where('document_date', $params['date']);
}
if(isset($params['dsid']))
{
$this->db->where('document_skpd_id', $params['dsid']);
}
if(isset($params['status']))
{
$this->db->where('document_is_published', $params['status']);
}
if(isset($params['document_sync']))
{
$this->db->where('document_sync', $params['document_sync']);
}
if(isset($params['sync']))
{
$this->db->reset_query();
$this->db->select('document.*');
$this->db->where('document_sync', $params['sync']);
}
if(isset($params['limit']))
{
if(!isset($params['offset']))
{
$params['offset'] = NULL;
}
$this->db->limit($params['limit'], $params['offset']);
}
if(isset($params['order_by']))
{
$this->db->order_by($params['order_by'], 'desc');
}
else
{
$this->db->order_by('document_date', 'desc');
}
$this->db->select('document.document_id');
$this->db->join('user_desktop', 'user_desktop.user_desktop_id = document.operator_id');
$this->db->join('(SELECT document_id, MAX(document_file_id) AS document_file_max_id FROM document_file GROUP BY document_id) AS document_file_max', 'document.document_id = document_file_max.document_id', 'left', FALSE);
$this->db->join('document_file', 'document_file.document_file_id = document_file_max.document_file_max_id', 'left');
$this->db->join('document_type', 'document_type.document_type_id = document.type_id');
$this->db->join('document_form', 'document_form.document_form_id = document.form_id');
$this->db->join('document_category', 'document_category.category_id = document.category_id');
$this->db->join('skpd', 'skpd.skpd_id = document.skpd_id');
$res = $this->db->get('document');
if(isset($params['id']))
{
return $res->row_array();
}
else
{
return $res->result_array();
}
}
Please master how to fix it ? whst is problem on my pagination
Please try this :
$config['base_url'] = site_url('document/index/'.
$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd.'/'
);
$config['uri_segment'] = 8;
in your base_url you missed out / at the end and codeigniter places offset for pagination. Hence, uri_segment would be 8.
Helo. I’m trying to make a items pagination. I have 3 function, first displaying category, 2nd displaying sucategory. 3rd displaying items is cold get_books_by_subcategory. 3rd function get a segment->url(3) argumnet, i want to make a pagination in the same function. but i cant do it.
This is functions code in controller:
function get_category()
{
$query = $this->Kategorie_model->get_category();
$this->response['podkategorie'] = '';
$this->response['kategorie'] = '';
$podkategorie = '';
if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
$podkategorie = $this->get_sub_category($item->CAT_ID);
$this->response['kategorie'] .= $this->load->view('Ksiegarnia/left', array('kategorie' =>$item, 'podkategorie'=>$podkategorie), true);
}
}
$data = $this->response['kategorie'];
return $data;
}
function get_sub_category($id)
{
$this->response['wynik'] = '';
$query = $this->Kategorie_model->get_sub_category($id);
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$link = site_url('ksiegarnia/get_books_by_subcategory/'.$row->SUBC_ID);
$this->response['wynik'] .= '<div class="subcat_name">'.$row->SUBC_Name.'</div>';
}
}
else
{
$this->response['wynik'] = '<H1>BRAK DANYCH </H1>';
}
return $this->response['wynik'];
}
function get_books_by_subcategory()
{
$widok['center'] = '';
$widok['left'] = $this->get_category();
$widok['right'] = $this->load->view('Ksiegarnia/right', '', true);
$id = $this->uri->segment(3);
if(isset($id) and is_numeric($id))
{
$query = $this->Kategorie_model->get_books_by_subcategory($id, $this->uri->segment(4));
if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
$widok['center'] .= $this->load->view('Ksiegarnia/get_books', array('data' =>$item), true);
}
}
else
{
$widok['center'] = $this->load->view('Ksiegarnia/get_books', array('tytul' =>'<h1>brak danych</h1>'), true);;
}
$widok['center'] .= $this->pagination->create_links();
$this->load->view('Ksiegarnia/index', $widok);
}
}
And this is my model:
function get_books_by_subcategory($id, $offset=0)
{
$config['base_url'] = 'http://lukaszbielecki.cba.pl/ksiegarnia/CI/index.php/ksiegarnia/get_books_by_subcategory/'.$id;
$config['per_page'] = 7;
$this->db->where('SUB_CATEGORY_SUBC_ID', $id);
$config['total_rows'] = $this->db->get('books')->num_rows();
$config['num_links'] = 20;
$this->pagination->initialize($config);
return $this->db->get('books',$config['per_page'],$offset);
//$wynik = $this->db->query("Select * from books where SUB_CATEGORY_SUBC_ID = '".$id."'");
//return $wynik;
}
The arguments in url is changing, but dispalyin only a items from first subcategory.
Help, please.
On this line $widok['center'] = $this->load->view('Ksiegarnia/get_books', array('tytul' =>'<h1>brak danych</h1>'), true);; in your controller, you have an additional semicolon ; that is causing a syntax error.