Welcome Guest, Not a member yet? Register   Sign In
CI4 with join and pagination
#1

I have joined three tables but my pagination only gives me my post table fields and not fields from the other 2 tables. I can see in the debugging bar that the proper sql is being executed. I can run that sql directly in mysql and the expected results are returned (eg fields from all three tables). Why are the other fields from the other tables now available please?

Here is my controller;

Code:
function index(){
        $post_category_id = null; // null means all categories
        $category_is_published = 1; // 1 means only published articles
        $post_is_published = 1;  // 1 means only published articles
        $pagination = 1; // 1 means to the model to send back an object for pagination
        $articles_per_page = 6;
        $this->data['posts']    = $this->PostModel->getPostsByCategory($post_category_id, $category_is_published, $post_is_published, $pagination )->paginate($articles_per_page, 'bootstrap');
        $this->data['pager']    = $this->PostModel->pager;
        return view('Post/post_index', $this->data);
    }

This is the sql that is produced;

Code:
SELECT `post`.`post_id`, `post`.`post_category_id`, `post`.`post_title`, `post`.`post_slug`, `post`.`post_body`, `post`.`post_is_published`, `post`.`post_updated_at`, `post`.`post_created_at`, `post`.`post_user_id`, `post`.`post_image`, `user`.`name`, `user`.`email`, `category`.`category_id`, `category`.`category_user_id`, `category`.`category_name`, `category`.`category_is_published`, `category`.`category_created_at`, `category`.`category_updated_at` FROM `post` JOIN `category` ON `category`.`category_id` = `post`.`post_category_id` JOIN `user` ON `user`.`id` = `post`.`post_user_id` WHERE `post`.`post_is_published` = 1 AND `category`.`category_is_published` = 1 ORDER BY `post`.`post_updated_at` DESC

This is the view output;

Code:
[post_id] => 264
                    [post_category_id] => 93
                    [post_user_id] => 53
                    [post_title] => This is the last post
                    [post_slug] =>
                    [post_body] => some text
                   [post_is_published] => 1
                    [post_image] => IMG_20210420_151153_copy_1600x1200.jpg
                    [post_created_at] => 2021-06-05 10:19:13
                    [post_updated_at] => 2021-08-16 05:03:42
Reply


Messages In This Thread
CI4 with join and pagination - by spreaderman - 08-20-2021, 06:43 PM
RE: CI4 with join and pagination - by InsiteFX - 08-21-2021, 12:52 AM
RE: CI4 with join and pagination - by spreaderman - 08-21-2021, 01:20 AM
RE: CI4 with join and pagination - by paliz - 08-21-2021, 01:23 PM
RE: CI4 with join and pagination - by spreaderman - 08-21-2021, 06:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB