Pagination can not back to prev number - php

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.

Related

result ammount not showing correct

On my pagination results it is not showing correct for example it should show Showing 1 to 5 of 5 (1 Pages) on view but for some reason it is showing Showing -19 to 0 of 5 (1 Pages)
I am not sure why it is showing -19 should show 1 $the $data['results'] not working correct how can I fix it.
<?php
class Users_group extends MX_Controller {
public function index() {
$this->load->library('paginations');
$this->load->model('admin/user/model_user_group');
$data['title'] = "Users Group";
// Sort
if (null !==($this->uri->segment(3))) {
$sort = $this->uri->segment(3);
} else {
$sort = 'name';
}
// Order
if (null !==($this->uri->segment(4))) {
$order = $this->uri->segment(4);
} else {
$order = 'asc';
}
// Page
if (null !==($this->uri->segment(3))) {
$page = $this->uri->segment(3);
} else {
$page = 1;
}
$url = '';
// Sort
if (null !==($this->uri->segment(3))) {
$url .= $this->uri->segment(3);
}
// Order
if (null !==($this->uri->segment(4))) {
$url .= $this->uri->segment(4);
}
// Page Number
if (null !==($this->uri->segment(3))) {
$url .= $this->uri->segment(3);
}
$admin_limit = "20";
$filter_data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $admin_limit,
'limit' => $admin_limit
);
$user_group_total = $this->model_user_group->getTotalUserGroups();
$results = $this->model_user_group->getUserGroups($filter_data);
foreach ($results as $result) {
$data['user_groups'][] = array(
'user_group_id' => $result['user_group_id'],
'name' => $result['name'],
'edit' => site_url('admin/users_group/edit' .'/'. $result['user_group_id'] . $url)
);
}
$url = '';
if ($order == 'asc') {
$url .= 'desc';
} else {
$url .= 'asc';
}
$data['sort_name'] = site_url('admin/users_group' .'/'. 'name' .'/'. $url);
$url = '';
$paginations = new Paginations();
$paginations->total = $user_group_total;
$paginations->page = $page;
$paginations->limit = $admin_limit;
$paginations->url = site_url('admin/users_group' .'/'. $url . '{page}');
$data['pagination'] = $paginations->render();
$paginations_lang = "Showing %d to %d of %d (%d Pages)";
$data['results'] = sprintf($paginations_lang, ($user_group_total) ? (($page - 1) * $admin_limit) + 1 : 0, ((($page - 1) * $admin_limit) > ($user_group_total - $admin_limit)) ? $user_group_total : ((($page - 1) * $admin_limit) + $admin_limit), $user_group_total, ceil($user_group_total / $admin_limit));
$data['sort'] = $sort;
$data['order'] = $order;
$this->load->view('template/user/users_group_list.tpl', $data);
}
public function getForm() {
$data['title'] = "Users Group";
$this->load->view('template/user/users_group_form.tpl', $data);
}
}

Laravel : search or filter the collection

I have this issue while filtering or searching through a collection
http://laravel.io/bin/vj115 check the url for code.
What i am trying to do is filter a collection by get method (from url ofcourse)
But only it only works when Input::get('category') has value else nothing works.
Could you please check the code and let me know what need to be fixed?
Thanks.
===== Real Code just incase the link is broken in future (edited)=============
public function anyIndex() {
$id = Input::get('id');
$brand = Brand::firstOrNew(array('id' => $id));
$paginate = Misc::getSettings('admin-pagination');
$page_no = isset($_GET['page']) ? $_GET['page'] : 1;
$i = ($paginate * $page_no) - ($paginate - 1);
$appends = false;
$newBrands = new Brand;
if (Input::get('category')) {
$brandCat = BrandCategory::find(Input::get('category'));
$newBrands = $brandCat->brands();
$appends['category'] = Input::get('category');
}
if (Input::get('status')) {
$status = Input::get('status') == 'published' ? 1 : 0;
$newBrands->where('is_active', '=', $status);
$appends['status'] = Input::get('status');
}
if (Input::get('order_by') || Input::get('order')) {
if (Input::get('order_by')) {
$order_by = Input::get('order_by');
$appends['order_by'] = Input::get('order_by');
} else {
$order_by = 'name';
}
if (Input::get('order')) {
$order = Input::get('order');
$appends['order'] = Input::get('order');
} else {
$order = 'asc';
}
$order = Input::get('order') ? Input::get('order') : 'asc';
$newBrands->orderBy($order_by, $order);
}
$brands = $newBrands->paginate($paginate);
$brand_categories_list = new BrandCategory;
$selected_cats = array();
if ($id != "") {
$selected_cats = $brand->categories->lists('id');
}
return View::make('admin.brands.index')
->with(array(
'selected_cats' => $selected_cats,
'brand' => $brand,
'brands' => $brands,
'brand_categories_list' => $brand_categories_list->lists('name', 'id'),
'appends' => $appends,
'i' => $i
));
}
Thanks to Dave.. I solved it as :
public function anyIndex() {
$id = Input::get('id');
$brand = Brand::firstOrNew(array('id' => $id));
$paginate = Misc::getSettings('admin-pagination');
$page_no = isset($_GET['page']) ? $_GET['page'] : 1;
$i = ($paginate * $page_no) - ($paginate - 1);
$appends = false;
if (Input::has('category')) {
$brandCat = BrandCategory::find(Input::get('category'));
$newBrands = $brandCat->brands();
$appends['category'] = Input::get('category');
} else {
$newBrands = Brand::limit(-1);
}
if (Input::has('status')) {
$status = Input::get('status') == 'published' ? 1 : 0;
$newBrands->where('is_active', '=', $status);
$appends['status'] = Input::get('status');
}
if (Input::has('order_by') || Input::has('order')) {
if (Input::has('order_by')) {
$order_by = Input::get('order_by');
$appends['order_by'] = Input::get('order_by');
} else {
$order_by = 'name';
}
if (Input::has('order')) {
$order = Input::get('order');
$appends['order'] = Input::get('order');
} else {
$order = 'asc';
}
$order = Input::get('order') ? Input::get('order') : 'asc';
$newBrands->orderBy($order_by, $order);
}else{
$newBrands->orderBy('name', 'asc');
}
$brands = $newBrands->paginate($paginate);
/* $queries = DB::getQueryLog();
$last_query = end($queries);
dd($last_query); */
$brand_categories_list = new BrandCategory;
$selected_cats = array();
if ($id != "") {
$selected_cats = $brand->categories->lists('id');
}
return View::make('admin.brands.index')
->with(
array(
'selected_cats' => $selected_cats,
'brand' => $brand,
'brands' => $brands,
'brand_categories_list' => $brand_categories_list->lists('name', 'id'),
'appends' => $appends,
'i' => $i)
);
}
I suspect it has to do with how you are using Eloquent. You can't simply apply methods to the object if it was created using the "new" keyword.
$newBrands = new Brand;
// This won't work
$newBrands->where('is_active', '=', $status);
// This will work
$newBrands = $newBrands->where('is_active', '=', $status);
It will work if you create it statically along with a method.
$newBrands = Brand::limit(100);
// This will work
$newBrands->where('is_active', '=', $status);
Fluent (DB) works the same way.
$newBrands = DB::table('brands');
// This wil work
$newBrands->where('is_active', '=', $status);
here I am searching the username(s) based on the displayname or fullname or email. therefore, the $request->filled('name of your input') is the solution.
$usernames = (new User())->newQuery(); //where User is the model
if($request->filled('email')){
$usernames->orWhere('email',$request->email);
}
if($request->filled('full_name')){
$usernames->orWhere('full_name',$request->full_name);
} if($request->filled('display_name')){
$usernames->orWhere('display_name',$request->display_name);
}
$usernames = $usernames->pluck('username')->toArray();

Trying to get property of non-object in model codeigniter

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;

Issues with PHP for loop entering names into database

I am using the following code to enter submitted names into the database. The code, when working correctly, should capture the names and other information submitted in the form and create three unique entries in the database. This is not happening. Instead the code is capturing the last name in the three pack and entering its information into the database. You can view the form here beta website. The payment processing script is disabled on the form. What do I need to change in the for loop code to fix this issue? Any assistance is greatly appreciated. Thank you. I have added all of the code that is used in the script below. Hopefully this will give you a better understanding of what is going on in the script.
class DreamModelDream extends JModel {
function getDetails()
{
$session = JFactory::getSession();
if($session->get('dreamticket'))
{
return $session->get('dreamticket');
}
$data = new stdClass();
$data->tickets = -1;
$data->fiftytickets = '';
$data->qty = 0;
$data->fiftyqty = 0;
$data->firstname = '';
$data->firstname2 = '';
$data->firstname3 = '';
$data->lastname = '';
$data->lastname2 = '';
$data->lastname3 = '';
$data->address = '';
$data->address2 = '';
$data->address3 = '';
$data->city = '';
$data->city2 = '';
$data->city3 = '';
$data->postal = '';
$data->postal2 = '';
$data->postal3 = '';
$data->phone = '';
$data->phone2 = '';
$data->phone3 = '';
$data->altphone = '';
$data->altphone2 = '';
$data->altphone3 = '';
$data->email = '';
$data->email2 = '';
$data->email3 = '';
$data->giftname = '';
$data->giftaddress = '';
$data->giftcity = '';
$data->giftpostal = '';
$data->sec_firstname = '';
$data->sec_firstname2 = '';
$data->sec_firstname3 = '';
$data->sec_lastname = '';
$data->sec_lastname2 = '';
$data->sec_lastname3 = '';
$data->agegroup = 0;
$data->expm = 0;
$data->expy = 0;
$data->nameoncard = '';
$data->cctype = '';
$data->ccnum = '';
$data->Media_Radio = false;
$data->Media_TV = false;
$data->Media_Newspaper = false;
$data->Media_Mail = false;
$data->Media_Web = false;
$data->Media_Kinsmen_Member = false;
$data->Media_Other = false;
$data->Radio_CJCY = false;
$data->Radio_MY96 = false;
$data->Radio_ROCK = false;
$data->Radio_CHAT = false;
$data->Radio_POWER = false;
$data->Radio_Other = false;
$data->total = false;
$data->billingphone = '';
$data->agree = 0;
$data->ord_type = 0;
$data->creditcard = '';
$data->user_ip = $_SERVER['REMOTE_ADDR'];
return $data;
}
function getConfirmDetails()
{
$post = JRequest::get('post');
$ticket = new stdClass();
foreach($post as $key => $value)
{
$ticket->$key = $value;
}
$session = JFactory::getSession();
$session->set('dreamticket', $ticket);
if(!strlen($post['firstname'])){
return "Your first name is missing<br>";
}
if(!strlen($post['lastname'])){
return "Your last name is missing<br>";
}
if(!strlen($post['address'])){
return "Your address is missing<br>";
}
if(!strlen($post['city'])){
return "Your city is missing<br>";
}
if(!strlen($post['postal'])){
return "Your postal code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal'])) {
//return "Your postal code is invalid for this province<br>";
}
if(!strlen($post['phone'])){
return "Your phone number is missing<br>";
}
if(!strlen($post['email'])){
return "Your email is missing<br>";
}
if($post['tickets'] == '-1'){
////////// TICKET 2
if(!strlen($post['firstname2'])){
return "Your first2 name is missing<br>";
}
if(!strlen($post['lastname2'])){
return "Your last2 name is missing<br>";
}
if(!strlen($post['address2'])){
return "Your address2 is missing<br>";
}
if(!strlen($post['city2'])){
return "Your city2 is missing<br>";
}
if(!strlen($post['postal2'])){
return "Your postal2 code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal2'])) {
//return "Your postal2 code is invalid for this province<br>";
}
if(!strlen($post['phone2'])){
return "Your phone number2 is missing<br>";
}
/////////////Ticket 3
if(!strlen($post['firstname3'])){
return "Your first name3 is missing<br>";
}
if(!strlen($post['lastname3'])){
return "Your last name3 is missing<br>";
}
if(!strlen($post['address3'])){
return "Your address3 is missing<br>";
}
if(!strlen($post['city3'])){
return "Your city3 is missing<br>";
}
if(!strlen($post['postal3'])){
return "Your postal code3 is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal3'])) {
//return "Your postal code3 is invalid for this province<br>";
}
if(!strlen($post['phone3'])){
return "Your phone number3 is missing<br>";
}
}
//////// END TICKET CHECK
if(!strlen($post['nameoncard'])){
return "Your Name on Credit Card is missing<br>";
}
if($post['cctype'] == "Please select one"){
return "Your Credit Card Type is missing<br>";
}
if(!strlen($post['ccnum'])){
return "Your Credit Card Number is missing<br>";
}
if(!strlen($post['billingphone'])){
return "Your billing phone number is missing<br>";
}
if(!strlen($post['agree'])){
return "Your must agree to the Lottery rules in order to proceed<br>";
}
return $ticket;
}
function process()
{
$user = JFactory::getUser();
jimport('joomla.database.table');
$params = JComponentHelper::getParams('com_dream');
$session = JFactory::getSession();
$data = $session->get('dreamticket');
if(!is_object($data))
{
return false;
}
$dif = strtotime("-1 hour");
$timestamp = date("F j, Y, g:i a",$dif);
$ord_id = date('ymdHis') . rand(1000,9999);
$ticket_total = (int) (($data->tickets == '-1') ? '250' : (int) $data->tickets * 100);
$fiftyticket_total = (int) (($data->fiftytickets == '0') ? '' : (int) $data->fiftytickets * 10);
$ordertotal = $ticket_total + $fiftyticket_total;
if(strlen($data->expm) == 1)
{
$data->expm = '0'.$data->expm;
}
if(strlen($data->expy) != 2)
{
$data->expy = substr($data->expy, 2, 2);
}
$data->total = $ordertotal;
JTable::addIncludePath(JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_dream'.DS.'tables');
$table = JTable::getInstance('Tickets', 'Table');
$table->auth = $auth;
$table->billingphone = $data->billingphone;
$table->Media_Radio = isset($data->Media_Radio) ? 1 : 0;
$table->Media_TV = isset($data->Media_TV) ? 1 : 0;
$table->Media_Newspaper = isset($data->Media_Newspaper) ? 1 : 0;
$table->Media_Mail = isset($data->Media_Mail) ? 1 : 0;
$table->Media_Web = isset($data->Media_Web) ? 1 : 0;
$table->Media_Kinsmen_Member = isset($data->Media_Kinsmen_Member) ? 1 : 0;
$table->Media_Other = isset($data->Media_Other) ? 1 : 0;
$table->Radio_CJCY = isset($data->Radio_CJCY) ? 1 : 0;
$table->Radio_MY96 = isset($data->Radio_MY96) ? 1 : 0;
$table->Radio_ROCK = isset($data->Radio_ROCK) ? 1 : 0;
$table->Radio_CHAT = isset($data->Radio_CHAT) ? 1 : 0;
$table->Radio_POWER = isset($data->Radio_POWER) ? 1 : 0;
$table->Radio_Other = isset($data->Radio_Other) ? 1 : 0;
$table->agegroup = $data->agegroup;
$table->orderdate = date('Y-m-d H:i:s');
$table->ip = $_SERVER['REMOTE_ADDR'];
$table->ord_type = ($user->get('id') > 0) ? 'CallCentre' : 'online';
$table->ord_id = $ord_id;
if($data->tickets == '0') {
$table->ticket_type = 'None';
} elseif($data->tickets == '-1') {
$table->ticket_type = '3Pack';
} elseif($data->tickets == '1') {
$table->ticket_type = '1ticket';
} elseif($data->tickets == '5') {
$table->ticket_type = '8tickets';
}
if($data->fiftytickets == '0') {
$table->fiftyticket_type = 'None';
} elseif($data->fiftytickets == '1') {
$table->fiftyticket_type = '1ticket';
} elseif($data->fiftytickets == '2') {
$table->fiftyticket_type = '3tickets';
}
$table->province = 'AB';
$table->creditcard = $data->cctype;
if(isset($data->giftpurchase)) {
$table->giftname = $data->giftname;
$table->giftadress = $data->giftadress;
$table->giftcity = $data->giftcity;
$table->giftpostal = $data->giftpostal;
}
$data->ord_id = $ord_id;
$tickets = 1;
$table->qty = $data->tickets;
if($data->tickets === '-1')
{
$tickets = 3;
$table->qty = 3;
} elseif($data->tickets === '1')
{
$tickets = 1;
$table->qty = 1;
} elseif($data->tickets === '5')
{
$tickets = 8;
$table->qty = 8;
}
$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;
$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
if($data->tickets === '-1' || $data->tickets === '5')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}
}
$fiftytickets = 1;
$table->fiftyqty = $data->fiftytickets;
if($data->fiftytickets === '1')
{
$fiftytickets = 1;
$table->fiftyqty = 1;
} elseif($data->fiftytickets === '2')
{
$fiftytickets = 3;
$table->fiftyqty = 3;
}
$table->order_total = $data->total;
$table->store();
//sending confirmation mail
$mailcontent = '';
for($i = 0; $i < $data->tickets; $i++)
I have figured out the issues with the for loop. The fiftytickets code needed to be moved above the for loop and the $table->store() function needed to be moved into the for loop and placed after the $table->id line. Now when a ticket or tickets are purchased, three entries with the same name or unique names are inserted into the database.

Regarding pagination in cakephp 2.0 with order by

How to deal with order by with different models.For e.g. i have an CareseekerJob model which is in association(belongsTO) with city,state,category and user model.I am doing searching and want to sort the job with price but it is taking by default paging of job table.
Please refer the code:-
$searchdata = array();
$conditioncat = '';
$conditionsearch = '';
if(!empty($categories) && $categories!='-1')
{
$conditioncat = 'CareseekerJob.category_id IN ('.$categories.') ';
}
if($categories == '-1')
{
$conditionserv = '(1 = 1) ';
}
$conditionserv = '';
if(!empty($services) && $services!='-1')
{
$serviceses = explode(',',$services);
$servicename = '';
$con = '(1 = 1) AND '; $i='0';
$servicename = '';
foreach($serviceses as $key=>$value)
{ $i++;
$servicedata = $this->Service->find('first',array('conditions'=>array('Service.id'=>$value)));
$servicename = $servicedata['Service']['name'];
$con .= '(CareseekerJob.services LIKE "%'.$servicename.'%")' ;
if(count($serviceses) == $i){
$con .= ' ';
}else{
$con .= ' OR ';
}
}
$conditionserv = $con;
}
if($services == '-1')
{
$conditionserv = '(1 = 1) ';
}
$conditiontime = '';
if($timingess != '1')
{
$start = '';
$end = '';
if($timingess == 'morning')
{
$start = date('H:i:s',strtotime('00:00:00'));
$end = date('H:i:s',strtotime('11:59:00'));
}
elseif($timingess == 'afternoon')
{
$start = date('H:i:s',strtotime('11:59:00'));
$end = date('H:i:s',strtotime('16:00:00'));
}
elseif($timingess == 'evening')
{
$start = date('H:i:s',strtotime('16:00:00'));
$end = date('H:i:s',strtotime('20:00:00'));
}
elseif($timingess == 'night')
{
$start = date('H:i:s',strtotime('20:00:00'));
$end = date('H:i:s',strtotime('23:59:00'));
}
elseif($timingess == 'morning,afternoon')
{
$start = date('H:i:s',strtotime('00:00:00'));
$end = date('H:i:s',strtotime('16:00:00'));
}
elseif($timingess == 'morning,evening')
{
$start = date('H:i:s',strtotime('00:00:00'));
$end = date('H:i:s',strtotime('20:00:00'));
}
elseif($timingess == 'morning,afternoon,evening')
{
$start = date('H:i:s',strtotime('00:00:00'));
$end = date('H:i:s',strtotime('20:00:00'));
}
elseif($timingess == 'morning,afternoon,evening,night')
{
$start = date('H:i:s',strtotime('00:00:00'));
$end = date('H:i:s',strtotime('23:59:00'));
}
$conditiontime = "( TIME(CareseekerJob.starttime) >= TIME('".$start."') and TIME(CareseekerJob.starttime) <= TIME('".$end."') ) ";
}
if($timingess == '1')
{
$conditiontime = '(1 = 1) ';
}
$conditionsearch = "";
$conditionZip = "";
if($searchtext != 1)
{
if(is_numeric($searchtext))
{
$url1 = "https://maps.googleapis.com/maps/api/geocode/xml?address=" . $searchtext . "&sensor=false";
$details = simplexml_load_file($url1);
if ($details->status == 'OK') {
$sourceLat = $details->result->geometry->location->lat;
$sourceLon = $details->result->geometry->location->lng;
$radiusKm = 160.934;
$proximity = $this->Radiussearch->mathGeoProximity($sourceLat, $sourceLon, $radiusKm);
$latmin=min($proximity["latitudeMin"],$proximity["latitudeMax"]);
$latmax=max($proximity["latitudeMin"],$proximity["latitudeMax"]);
$lonmin=min($proximity["longitudeMin"],$proximity["longitudeMax"]);
$lonmax=max($proximity["longitudeMin"],$proximity["longitudeMax"]);
$conditionZip=array("CareseekerJob.lat BETWEEN ? AND ?" => array(number_format(min($proximity["latitudeMin"],$proximity["latitudeMax"]), 12, ".", ""), number_format(max($proximity["latitudeMin"],$proximity["latitudeMax"]), 12, ".", "")),"CareseekerJob.long BETWEEN ? AND ?"=> array(number_format(max($proximity["longitudeMin"],$proximity["longitudeMax"]), 12, ".", ""),number_format(min($proximity["longitudeMin"],$proximity["longitudeMax"]), 12, ".", "")));
}
$conditionsearch = '(1 = 1)';
}
else{
$conditionsearch= array('OR'=>array('CareseekerJob.title LIKE'=>'%'.$searchtext.'%','CareseekerJob.zipcode'=>$searchtext));
}
}else{
$conditionZip = '(1 = 1)';
$conditionsearch = '(1 = 1)';
}
if($sort =='recent' )
{
$condition= array('CareseekerJob.job_status'=>'jobactive','CareseekerJob.is_deleted'=>0,'CareseekerJob.status'=>'active');
$this->paginate = array(
'conditions' => array('AND'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionZip)),
'limit' => 4,
'order' => array(
'CareseekerJob.id' => 'desc'
)
);
$searchdata = $this->paginate('CareseekerJob');
}
elseif($sort =='distance' )
{
$condition= array('CareseekerJob.job_status'=>'jobactive','CareseekerJob.is_deleted'=>0,'CareseekerJob.status'=>'active');
$this->paginate = array(
'conditions' => array('AND'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionZip)),
'limit' => 4,
'order' => array(
'CareseekerJob.lat' => 'desc'
),
);
$searchdata = $this->paginate('CareseekerJob');
}elseif($sort =='price')
{
$condition= array('CareseekerJob.job_status'=>'jobactive','CareseekerJob.is_deleted'=>0,'CareseekerJob.status'=>'active');
$this->paginate = array(
'conditions' => array('AND'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionZip)),
'limit' => 4,
'order' => array(
'CareseekerJob.rate' => 'desc'
)
);
$searchdata = $this->paginate('CareseekerJob');
}

Categories