Welcome Guest, Not a member yet? Register   Sign In
How to make pagination for search results
#2

Below, a basic and small example of pagination, not considering the arguments and type of query used.
Model:
PHP Code:
<?php
namespace App\Models;

use 
CodeIgniter\Model;

class 
TesteModel extends Model
{
    protected $table  'names';
    protected $primaryKey 'id';
    protected $returnType 'object';


    public function getNames($id)
    {
        $db $this->db;
        $query $db->table('names')
            ->where('id'$id)
            ->get();

        return $query->getResult();
    }

    public function numNames($id)
    {
        $db $this->db;        
        $count 
$db->table('names');
        $count->where('prof2 > 0');

        return $count->countAllResults();
    }


Controller:
PHP Code:
<?php

namespace App\Controllers;

// 20210207

use App\Models\TesteModel;
use 
CodeIgniter\Controller;

class 
Teste extends Controller
{

    public function names($id)
    {

        $testeModel = new TesteModel();

        $data = [
            'player'  => $testeModel->where('prof2 > 0')
                ->orderBy('name''asc')
                ->paginate(20),
            'pager'  => $testeModel->pager,
            'total'  => $testeModel->numMames($id)
        ];

        $header = [
            'css'  => 'teste',
            'title' => 'Teste - wdeda '
        ];

        echo view('templates/header'$header);
        echo view('teste'$data);
        echo view('templates/footer');

}


Reply


Messages In This Thread
RE: How to make pagination for search results - by wdeda - 09-29-2021, 02:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB