Welcome Guest, Not a member yet? Register   Sign In
Help with Codeigniter v4 pagination Library
#6

(This post was last modified: 03-23-2021, 01:25 AM by venance.)

(03-22-2021, 08:47 PM)InsiteFX Wrote: Pager works just fine with Query Builder, do what you want in the model with Query Build
but do not tell it to return a result set instead return $this

Then it's chainable.

Do you mean I can do this way:

$this->db->query("SELECT * FROM table");
return $this;

(03-23-2021, 12:49 AM)venance Wrote:
(03-22-2021, 08:47 PM)InsiteFX Wrote: Pager works just fine with Query Builder, do what you want in the model with Query Build
but do not tell it to return a result set instead return $this

Then it's chainable.

Do you mean I can do this way:

$this->db->query("SELECT * FROM table");
return $this;

I tried to perform my query like this to
//my Model
PHP Code:
    public function getData(){       
        $this
->table 'province_income';
        $sql "
        SELECT Date, 
        SUM(Income) as Income, SUM(Expense) as Expense, SUM(Income) - SUM(Expense) as Profit 
        FROM ( 
                  SELECT 
                      province_income.date as Date, 
                      province_income.amount as Income, 
                      0 as Expense 
                  FROM province_income
                  UNION ALL 
                  SELECT 
                      province_expenses.date as Date, 
                      0 as Income, 
                     province_expenses.amount as Expense 
                  FROM province_expenses
           ) as t 
        GROUP BY Date
      "
;

        $this->db->query($sql);
        return $this;
    

// my controller
PHP Code:
public function index(){
        $data['results'] =$this->model->getData()->paginate(1)
        $data['pager']  $this->model->pager->links();
        return view('Test/index'$data);



//View
PHP Code:
<?php foreach ($results as $result): ?>
    <div>
        <p> <?= $result['Date'?></p>
        <p> <?= $result['Income'?></p>
        <p> <?= $result['Expense'?></p>
        <p> <?= $result['Profit'?></p>
    </div>
<?php endforeach;?>

But I get error:
PHP Code:
Undefined indexDate
Undefined index
Income
Undefined index
:Expense
Undefined index
Profit 

How can I make it work?
Reply


Messages In This Thread
RE: Help with Codeigniter v4 pagination Library - by venance - 03-23-2021, 12:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB