I've used codeigniter to make an easy search, no ajax or something, and I want to integrate the pagination class, I have read some examples and they use a library like this $this->table->generate($results); and I need in each result a button to edit that entry. I already did, but now with that way of showing the pagination I have a big problem, please, could anyone help me with this issue? I just need a clue or something to find in CI
I put here my model, controller and view, just in case
controller
public function searchdescription()
{
//$keyword = $this->input->post('keyword');
$keyword = $_POST['keyword'];
$this->load->model('searchdesc/searchdesc_model');
$data['retorno'] = $this->searchdesc_model->querydb($keyword);
$this->load->view('searchdesc/searchresults_view', $data);
}
model
function querydb($data,$num, $offset)
{
$queryresult = $this->db->query("select * from data where deleteflag=0 and title like '%$data%' or text like '%$data%' LIMIT $num, $offset ");
return $queryresult->result_array();
}
view
foreach ($retorno as $val)
{
echo $val['id'];
echo $val['title'];
echo $val['text'];
...here are some forms autocreated in each row that i need to keep making it
}
Here is an example (not using a model)
public function big()
{
$this->load->library('pagination');
$this->load->library('table');
$config['base_url'] = base_url().'/site/big/';
$where = "bot = '2' OR bot = '0'";
$this->db->where($where);
$config['total_rows'] = $this->db->count_all_results('visitors');
$config['per_page'] = 15;
//$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$where = "bot = '2' OR bot = '0'";
$this->db->where($where);
$this->db->select('id, ip, date, page, host, agent, spammer, country, total, refer');
$this->db->order_by("date", "DESC");
$data['records'] = $this->db->get('visitors', $config['per_page'], $this->uri->segment(3));
$this->table->set_heading('Id', 'IP', 'Date', 'Page', 'Host', 'Agent', 'Spam', 'Country', 'Total', 'Referer');
$this->db->select_sum('total', 'trips');
$query = $this->db->get('visitors');
$data['trips'] = $query->result();
$this->load->view('site_view', $data);
}
In the view where I want the table:
<?php echo $this->table->generate($records); ?>
<?php echo $this->pagination->create_links(); ?>
to add buttons in the rows do something like this
foreach($records as $row){
$row->title = ucwords($row->title);
$this->table->add_row(
$row->date,
anchor("main/blog_view/$row->id", $row->title),
$row->status,
anchor("main/delete/$row->id", $row->id, array('onClick' => "return confirm('Are you sure you want to delete?')")),
anchor("main/fill_form/$row->id", $row->id)
);
}
$table = $this->table->generate();
echo $table;
Of course you will modify to fit your needs
Related
I'm relatively new in Code Igniter and I'm trying to use the Code Igniter pagination class for the first time. I'm trying to get some rows in my database table, depending on the state, lga and category selected by the user. These three are passed to the function as parameters. I have followed the process I found on SO and some other sites to implement pagination on the page, and it seems to work, except that it doesn't return all the rows that has the specified parameters.
This what I have:
Model - Posts_model.php
public function count_lga_cat_posts($state, $lga, $category) {
return $this->db->get_where('lga_posts', array('state' => $state, 'lga' => $lga, 'category' => $category, 'display' => 'true'))->num_rows();
}
public function fetch_lga_cat_data($limit, $start) {
$this->db->limit($limit, $start);
$this->db->order_by("id", "desc");
$query = $this->db->get("lga_posts");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
Controller - Lga_posts.php
public function selected_state_lga_posts_category($state, $lga, $category)
{
//config for pagination
$config = array();
$uri_seg = 5;
$config["base_url"] = base_url('state2/'.$state.'/'.$lga.'/'.$category); //as specified in routes
$config["total_rows"] = $this->posts_model->count_lga_cat_posts($state, $lga, $category);
$config["per_page"] = 3;
$config["uri_segment"] = $uri_seg;
$config['use_page_numbers'] = TRUE;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['first_link'] = 'Back to first page';
$config['next_link'] = 'View more posts';
$config['prev_link'] = 'Previous posts';
$config['last_link'] = 'Jump to last page';
$config['display_pages'] = FALSE;
$this->pagination->initialize($config);
$page = ($this->uri->segment($uri_seg))? $this->uri->segment($uri_seg) : 0;
$this->db->where(array('state' => $state, 'lga' => $lga, 'category' => $category, 'display' => 'true'));
$data["results"] = $this->posts_model->fetch_lga_cat_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links );
$data['state'] = $state;
$data['lga'] = $lga;
$data['category'] = $category;
$this->load->view('posts/lga/selected_state_lga_posts_category', $data);
When I load this page, everything seems to work fine, the pagination links are working as expected, but some rows in the table are not pulled, even though they have the same parameters as the ones that were pulled and displayed. If I change per_page config to 1, the last page gives an error "invalid argument in foreach" or something similar. I wonder if it has something to do with my query, since I do not want to get all the rows in the table, but the ones that have the selected parameters i.e. state, lga and category.
Can someone please point out to me what I'm doing wrong?
So, I have been trying to get this delete function to work now for a while.
At the bottom of the foreach I have a delete function. The funtion itself does work, however it always selects the post id of 1.
View
<div><?php foreach($posts as $post) : ?>
<hr>
<h3><?php echo $post['title']; ?></h3>
<div class="row">
<div class="col-md-3">
<img class="post-thumb" src="<?php echo site_url(); ?>posts/image/<?php echo $post['post_image']; ?>">
</div>
<div class="col-md-9">
<small class="post-date">Posted on: <?php echo $post['created_at']; ?> in <strong><?php echo $post['name']; ?></strong></small><br>
<?php echo word_limiter($post['body'], 60); ?>
<br><br>
<p><a class="btn btn-default" href="<?php echo site_url('/posts/'.$post['slug']); ?>">Read More</a></p>
</div>
</div>
<?php echo form_open('/posts/delete/'.$post['id']); ?>
<input type="submit" value="Delete" class="btn btn-danger">
</form>
Controller
public function posts($offset = 0){
// Pagination Config
$config['base_url'] = base_url() . 'admins/posts/';
$config['total_rows'] = $this->db->count_all('posts');
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['attributes'] = array('class' => 'pagination-link');
// Init Pagination
$this->pagination->initialize($config);
$data['title'] = 'Latest Posts';
$data['posts'] = $this->post_model->get_posts(FALSE, $config['per_page'], $offset);
$this->load->view('templates/header');
$this->load->view('admins/posts', $data);
$this->load->view('templates/footer');
}
Model
public function delete_post($id){
$image_file_name = $this->db->select('post_image')->get_where('posts', array('id' => $id))->row()->post_image;
$cwd = getcwd(); // save the current working directory
$image_file_path = $cwd."\\assets\\images\\posts\\";
chdir($image_file_path);
unlink($image_file_name);
chdir($cwd); // Restore the previous working directory
$this->db->where('id', $id);
$this->db->delete('posts');
return true;
}
EDIT:
get_posts in model
public function get_posts($slug = FALSE, $limit = FALSE, $offset = FALSE){
if($limit){
$this->db->limit($limit, $offset);
}
if($slug === FALSE){
$this->db->order_by('posts.id', 'DESC');
$this->db->join('categories', 'categories.id = posts.category_id');
$query = $this->db->get('posts');
return $query->result_array();
}
$query = $this->db->get_where('posts', array('slug' => $slug));
return $query->row_array();
}
The function does run and I get a confirmation message, so the only thing I am really confused about is the Id.
The whole thing is written using the CodeIgniter Framework.
Check your get_post model properly. From what you have, it looks like your query will get it's id from the category table.
Try this instead
public function get_posts($slug = FALSE, $limit = FALSE, $offset = FALSE){
if($limit){
$this->db->limit($limit, $offset);
}
if($slug === FALSE){
$this->db->select('posts.id AS id, posts.slug, posts.body, posts.created_at');
$this->db->from('posts, categories');
$this->db->where('categories.id = posts.category_id');
$query = $this->db->get();
return $query->result_array();
}
$query = $this->db->get_where('posts', array('slug' => $slug));
return $query->result_array();
}
Updating your join to LEFT JOIN or simple use WHERE
you are returning only 1 line with row_array() function so you should replace for result_array():
public function get_posts($slug = FALSE, $limit = FALSE, $offset = FALSE){
if($limit){
$this->db->limit($limit, $offset);
}
if($slug === FALSE){
$this->db->order_by('posts.id', 'DESC');
$this->db->join('categories', 'categories.id = posts.category_id');
$query = $this->db->get('posts');
return $query->result_array();
}else{
$query = $this->db->get_where('posts', array('slug' => $slug));
return $query->result_array();
}
}
Thanks to everyone, your answers helped me a lot and I learned a few new things about PHP. I tried implementing your Ideas and they solved the area of the problem I was asking about. In the end I decided to use a simple mysqli query to get the data I needed from the database. mysqli_query($con, "SELECT id,category_id,user_id,title,body,created_at FROM posts Order By id DESC");
May be i am wrong but i think its a foreach syntax issue,
because if you getting same id in all the
rows,
you need to write like,
<?php foreach ($posts as $post) : ?>
instead of,
<?php foreach ($posts as $post) { ?>
//your code goes here
<?php } ?>
I have a problem with pagination and codeigniter. I have a quick_searh view from witch I am submitting the information to a index controller function and there setting the pagination and calling the quick_search method to get the data I want. It just doesnt work . I've spent more then 5 hours rewriting those methods and even starting with quick_search and then passing to index function but nothing worked, please help.
public function index(){
// search parameters config
$lawyer_name = $this->input->post('lawyer_name');
$kanzlei = $this->input->post('kanzlei');
$area_of_expertise = $this->input->post('area_of_expertise');
$post_code = $this->input->post('post_code');
$city = $this->input->post('city');
$result = $this->quick_search(
$this->uri->segment(3),
$lawyer_name,
$kanzlei,
$area_of_expertise,
$post_code,
$city);
if(isset($result)){
// pagination config
$this->load->library('pagination');
$this->load->library('table');
$config['total_rows'] = count($result);
$config['base_url'] = 'http://localhost/anwalt/index.php/search/index';
$config['per_page'] = 5;
$config['num_links'] = 5;
$this->pagination->initialize($config);
$data['search_result_array'] = $result;
$data['main_content'] = 'pages/quick_search_results';
$this->load->view('templates/home_body_content', $data);
}
}
the quick_search function:
public function quick_search($offset, $lawyer_name, $kanzlei, $area_of_expertise, $post_code, $city){
// no input in the quick search
if( empty($lawyer_name) && empty($kanzlei) && empty($area_of_expertise)
&& empty($post_code) && empty($city))
{
$result = 'nothing';
} else {
$this->load->model('quick_search_model');
$result = $this->quick_search_model->get_search_results(
$offset,
$lawyer_name,
$kanzlei,
$area_of_expertise,
$post_code,
$city
);
}
return $result;
}
the sql is like this:
$sql = "SELECT users.user_id, users.canonical_name, first_name, last_name, city, phone_number, kanzlei
from users
inner join user_normal_aos
on users.user_id = user_normal_aos.user_id
inner join normal_areas_of_expertise
on user_normal_aos.normal_areas_of_expertise_id = normal_areas_of_expertise.normal_areas_of_expertise_id
where ".implode(" AND ", $where);
if(empty($offset)){
$offset = 0;
}
$sql = $sql." LIMIT ".$offset.", 4";
The data are displayed but I dont see the pagination in there .. and even when I want to change the url for segmenting it says I dont have any data.
The view is like:
<h1>Quick search results</h1>
<?php
if($search_result_array == "nothing"){
echo "<h3>You havent inputed anything</h3>";
} else {
echo $this->table->generate($search_result_array);
}
echo $this->pagination->create_links();
As per your search variables you can use this:
$lawyer_name = $this->input->post('lawyer_name');
$kanzlei = $this->input->post('kanzlei');
$area_of_expertise = $this->input->post('area_of_expertise');
$post_code = $this->input->post('post_code');
$city = $this->input->post('city');
/*pagination start*/
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/index/lawyer/'.$lawyer_name.'/kanzlei/'.$kanzlei.'/area_of_expertise/'.$area_of_expertise.'/post_code/'.$city.'/page/';
$config['total_rows'] = $this->model->count_all_results(); ###implement this function to count all the vodeos as per the search variables, just use the same function as "quick_search" but without the limit clause
$config['per_page'] = count($result);;
$config['uri_segment'] = 10;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['cur_tag_open'] = '<span class="active_page">';
$config['cur_tag_close'] = '</span>';
$this->pagination->initialize($config);
/*pagination end*/
You can not use $this->pagination->create_links(); method in view.
Use $data['pagination'] = $this->pagination->create_links(); in controller just before loading view
and echo $pagination in view
hope this will help you.
Can anyone explain why I cannot get a variable called $siteID to pass to another function within the same controller?
In the third function called "get_orders_by_site" I have loaded a different model, which returns information about 'orders' raised at the currently viewed building/site/property.
The sites controller works perfectly, first function lists a table with all my properties, then when one is clicked - the second function gets the siteID of that selection, and returns with further 'detail/data' - sites controller function1/2 all relate to the same model, and return information from the SAME table.
I'm trying to implement a third function, which will do a similar task, but return with information/data from a different table (the site.siteID, is also a FK in the orders.siteID table i've created in phpmyadmin).
If I need to explain further please let me know - Many thanks!
amended code
Sites Controller
<?php
class Sites extends CI_Controller {
//Searches for a list of sites
public function search($sort_by = 'site_title', $sort_order = 'asc', $offset = 0)
{
$limit = 20;
$data['columns'] = array(
'site_title' => 'Site Name',
'site_uprn' => 'Unique Property Reference'
);
$this->load->model('site_model');
$results = $this->site_model->get_sites($limit, $offset, $sort_by, $sort_order);
$data['sites'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
//pagination for list returned
$this->load->library('pagination');
$config = array ();
$config['base_url'] = site_url("Sites/search/$sort_by/$sort_order");
$config['total_rows'] = $data['num_results'];
$config['per_page'] = $limit;
$config['uri_segment'] = 5;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['sort_by'] = $sort_by;
$data['sort_order'] = $sort_order;
$this->load->view('search', $data);
}
//Displays individual site details
//passes selected siteID to the model, and returns only database/info for that particular building/property
public function details($siteID){
$this->load->model('site_model');
$data['site']=$this->site_model->get_site($siteID);
$this->load->view('site', $data);
$this->load->view('orders', $data);
}
// this second function should do a similar method as above, however I've loaded a different model, as i'm getting information from a different database table - but I still want the data returned to be limited by the building/site ID which the user selects.
public function orders_by_site($siteID, $sort_by = 'orderID', $sort_order = 'asc', $offset = 0)
{
$this->load->model('site_model');
$this->load->model('order_model');
$limit = 20;
$data['columns'] = array(
'orderID' => 'Order No.',
'initiated_date' => 'Initiated Date',
'target_date' => 'Target Date',
'status' => 'Status',
'priority' => 'Priority',
'trade_type' => 'Trade Type'
);
$results = $this->site_model->get_site($siteID);
$results = $this->order_model->get_orders($siteID, $limit, $offset, $sort_by, $sort_order);
$data['orders'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
//pagination for orders table
$this->load->library('pagination');
$config = array ();
$config['base_url'] = site_url("Orders/orders_by_site/$sort_by/$sort_order");
$config['total_rows'] = $data['num_results'];
$config['per_page'] = $limit;
$config['uri_segment'] = 6;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['sort_by'] = $sort_by;
$data['sort_order'] = $sort_order;
$this->load->view('orders', $data);
}
}
End Sites Controller
Site Model
//Get all site data
function get_sites($limit, $offset, $sort_by, $sort_order){
$sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
$sort_columns = array('site_title', 'site_uprn');
$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'site_title';
$q = $this->db->select('siteID, site_title, site_uprn')
->from('sites')
->limit($limit, $offset)
->order_by($sort_by, $sort_order);
$ret['rows'] = $q->get()->result();
//count query for sites
$q = $this->db->select('COUNT(*) as count', FALSE)
->from('sites');
$tmp = $q->get()->result();
$ret['num_rows'] = $tmp[0]->count;
return $ret;
}
//Get individual site data
function get_site($siteID){
$this->db->select()->from('sites')->where(array('siteID' => $siteID));
$query = $this->db->get();
return $query->first_row('array');
}
}
Orders Model
//order table
function get_orders($siteID, $orderID, $limit, $offset, $sort_by, $sort_order){
$sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
$sort_columns = array('orderID', 'initiated_date', 'target_date','completion_date','status','priority','total_amount','job_description','requestor_name','requestor_telno','trade_type');
$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'orderID';
$q = $this->db->select()->from('orders')->where(array('siteID' => $siteID))->limit($limit, $offset)->order_by($sort_by, $sort_order);
$ret['rows'] = $q->get()->result();
}
//order details
function get_order($orderID){
$this->db->select()->from('orders')->where(array('orderID' => $orderID));
$query = $this->db->get();
return $query->first_row('array');
}
}
Site View - only showing the extract where I'm trying to embed the orders view
<h5>Order Details</h5>
<?php include('orders.php')?>
</div>
</div>
</div>
Orders View
<div id="site_filter">
<div class="result_counter">
<h5>Found <?php echo $num_results; ?> Orders</h5>
</div>
<div class="pagination">
<?php if(strlen($pagination)): ?>
Page: <?php echo $pagination; ?>
<?php endif; ?>
</div>
</div>
<div class="clear_float"></div>
<table class="table">
<thead>
<?php foreach($columns as $column_name => $column_display): ?>
<th <?php if ($sort_by == $column_name) echo "class=\"sort_$sort_order\"" ?>>
<?php echo anchor("Sites/orders_by_site/$column_name/" .
(($sort_order == 'asc' && $sort_by == $column_name) ? 'desc' : 'asc') ,
$column_display); ?>
</th>
<?php endforeach; ?>
</thead>
<tbody>
<?php foreach($orders as $order): ?>
<tr>
<td><?php echo $order->orderID; ?></td>
<td><?php echo $order->initiated_date; ?></td>
<td><?php echo $order->target_date; ?></td>
<td><?php echo $order->status; ?></td>
<td><?php echo $order->priority; ?></td>
<td><?php echo $order->trade_type; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
OK, a couple of things here - and I'm gonna need some help
In the orders_by_site method, you're overwriting the results variable:
$results = $this->site_model->get_site($siteID);
$results = $this->order_model->get_orders($siteID, $limit, $offset, $sort_by, $sort_order);
Also, the way you're loading views is incorrect. You're loading your views like this:
$this->load->view('site', $data);
$this->load->view('orders', $data);
And what you need to be doing is this:
// you need to get the "contents" of the `orders` view in a variable
// and pass that to the `site` view
$data['orders'] = $this->load->view('orders', $data, TRUE);
$this->load->view('site', $data);
And change your site view to this:
<h5>Order Details</h5>
<?php echo $orders; ?>
</div>
</div>
</div>
I'm sure there's more going on than that, but that's all I can gather from what I've seen in your question and comments.
#swatkins -
Thank you very much for your help, you highlighted some issues I had overlooked - I've gone about this in a different fashion now.
Originally I was trying to use Active Record (i believe) to select data from one table, based on the selection of a record from a different table - and then pass this selection to another model and use it in a get_where statement.
I've managed to get this to work using the $this->uri->segment() method in my controller, and then passing this to the corresponding model.
Now I'm able to utilise the user selection of a 'building/propery' name, with it's address etc - and then I have a second model, which retrieves the 'orders/jobs' that have been raised at that building.
I have a controller with a method that looks something like this:
public function browsecategory($category_id)
{
//find any subcategories for this category
$this->load->model('category/category_model');
$this->load->model('category/product_category_model');
$records['categories'] = $this->category_model->find_all_by('parent_id', $category_id);
//add some product data too.
$records['products'] = $this->product_category_model->find_all_by('category_id', $category_id);
Template::set('records', $records);
Template::render();
}//end browsecategory
All the examples I've seen for the codeigniter pagination "stuff" is using one query.
I need to combine two data sets and serve on one view.
Any suggestions?
EDIT 1
I've tried to follow MDeSilva's suggestion below. And although the pagination object is correctly calculating the number of links to create, all items appear on all pages.
Here's the code in the model that gets the data:
public function get_categories_and_products($limit=12, $offset=0, $category_id=null)
{
print '<BR>the function got the following offeset:'.$offset;
$query = "(SELECT cat.category_id, cat.title, cat.image_thumb, cat.deleted, cat.display_weight ";
$query = $query."FROM bf_categories cat ";
$query = $query."WHERE cat.parent_id=".$category_id;
$query = $query." AND cat.category_id <>".$category_id;
$query = $query.") UNION (";
$query = $query."SELECT p.product_id, p.name, p.image_thumb, p.deleted , p.display_weight";
$query = $query." FROM bf_product p ";
$query = $query."Inner join bf_product_category cp ";
$query = $query."on p.product_id=cp.product_id ";
$query = $query."Where cp.category_id=".$category_id.")";
$this->db->limit($limit, $offset);
$catsandprods= $this->db->query($query);
return $catsandprods->result() ;
}
And here's the code in the controller:
public function browsecategory($category_id, $offset=0)
{
$this->load->library('pagination');
$total = $this->product_model->get_cats_prods_count($category_id);
$config['base_url'] = site_url('/product/browsecategory/'.$category_id);
$config['uri_segment'] = 4;
$config['total_rows'] = $total;
$config['per_page'] = 5;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$offset = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;
print $offset;
//Call the model function here to get the result,
$records= $this->product_model->get_categories_and_products(5,$offset,$category_id);
//add to breadcrumb trail
$this->build_bread_crumb_trail($category_id);
$breadcrumbs = $this->breadcrumbs->expand_to_hyperlinks();
Template::set('currentcategory',$category_id);
Template::set('breadcrumbs', $breadcrumbs);
Template::set('records', $records);
Template::render();
}
I've debugged and I can see that the line of code "$this->db->limit($limit, $offset);" in the model is not working. It always returns the full record set...
Can you tell me what I'm missing?
Thanks.
This is the way to generate pagination links in CI, for your requirement have a query with a join,
public function index($offset = 0) {
$language_id = 1;
$artwork_id = null;
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$artwork_id = $this->input->post('serach_artwork_id', TRUE) ? $this->input->post('serach_artwork_id', TRUE) : null;
$data['artwork_id'] = $artwork_id;
}
$this->load->library('pagination');
$limit = 10;
$total = $this->Artwork_model->get_artwork_count($language_id, $artwork_id);
$config['base_url'] = base_url().'artwork/index/';
$config['total_rows'] = $total;
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['first_link'] = '<< First';
$config['last_link'] = 'Last >>';
$config['next_link'] = 'Next ' . '>';
$config['prev_link'] = '<' . ' Previous';
$config['num_tag_open'] = '<span class="number">';
$config['num_tag_close'] = '</span>';
$config['cur_tag_open'] = '<span class="current"><a href="#">';
$config['cur_tag_close'] = '</a></span>';
$this->pagination->initialize($config);
//Call the model function here to get the result,
$data['artworks'] = $this->Artwork_model->get_artworks($language_id, $limit, $offset, $artwork_id);
$this->template->write('title', 'Artwork : Manage Artwork');
$this->template->write_view('content', 'artwork/index', $data);
$this->template->render();
}
Here is an example for query with multiple joins in the model
public function get_artworks($language_id = 1, $limit = 10, $offset = 0, $arwork_id = null)
{
$this->db->select('a.id, a.price, a.is_shop, at.title,at.status,at.date_added,ats.name as artist_name');
$this->db->from('artworks a');
$this->db->join('artwork_translations at', 'a.id = at.artwork_id');
$this->db->join('artists ats', 'a.artist_id = ats.id');
$this->db->where('at.language_id', $language_id);
if(!is_null($arwork_id) && !empty($arwork_id) && $arwork_id != 'all')
{
$this->db->where('a.id =', $arwork_id);
}
$this->db->order_by('a.id DESC');
$this->db->limit($limit, $offset);
$artworks = $this->db->get();
return $artworks->result();
}
In the View
<?= $this->pagination->create_links(); ?>
The pagination class doesn't care about the how the data source is constructed, just so you hand it the data result object it wants. So you would just pass limits & offsets into your data queries, or else pull all your data and slice it up afterwards.
However, I don't really understand how you are thinking to combine these different bits of data into a single result to display - are you trying to display all categories, then paginate the products? If so, you are set up incorrectly
Simply use PHP function array_merge
<?php $beginning = 'foo'; $end = array(1 => 'bar');
$result = array_merge((array)$beginning, (array)$end);
$this->load->view('view.php', $result);
?>
and extract according to keys for array used.
It is really simple & working