• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI 4 pagination problem

#1
How do I paginate only selected items from a table.

Controller:

PHP Code:
<?php 

namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Pageusersselect extends Controller
{        
    
public function showusers()
    {
        $Body['title'] = 'Dzielenie wybranych użytkowników na strony';
        
        $pager 
= \Config\Services::pager();
                
        $model 
= new \App\Models\ShowuserselectModel();
        
        $Body
['users'] = $model->PaginateUsers(10);
        $Body['pager'] = $model->pager;
        
        
echo view('showuser/index'$Body);
    }
}

?>

Model:
PHP Code:
<?php 

namespace App\Models;

use 
CodeIgniter\Model;

class 
ShowuserselectModel extends Model
{
    protected $table 'users';
    protected $primaryKey 'id';
    
    
public function PaginateUsers($HowMany)
    {
        $sql "SELECT * FROM users WHERE name LIKE '%n'";
        $Result $this->db->query($sql);
        $Result2 $Result->getRowArray();
        return $Result2;
    }
}

?>

View
PHP Code:
<!doctype html>
<
html lang="pl">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous" />
    <title><?php echo $title?></title>
    <style>
    ul.pagination li 
    {
        margin-left: 5px;
        margin-right: 5px;
    }
    </style>
  </head>
  <body>
    
    <div class="container">
      <div class="row">
        <div class="col-sm-1">
        </div>
        <div class="col-sm-10">
          
        <h1><?php echo $title?></h1>
        
        <table class="table table-bordered">
        <thead>
          <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Address</th>
            <th>City</th>
            <th>Date</th>
            <th>Personal number</th>
          </tr>
        </thead>
        <tbody>
          <?php 
          
if(isset($users))
          {
              foreach($users as $user)
              {
                  echo '<tr>
                    <td>'
.$user['id'].'</td>
                    <td>'
.$user['name'].'</td>
                    <td>'
.$user['address'].'</td>
                    <td>'
.$user['city'].'</td>
                    <td>'
.$user['date'].'</td>
                    <td>'
.$user['personalnumber'].'</td>
                  </tr>'
;
              }
          }
          ?>
        </tbody>
      </table>

      <!-- Pagination -->
      <div class="d-flex justify-content-end">
        <?php if(isset($pager))
        {
            $pager->setPath('pageusersselect');
            echo $pager->makeLinks($page10$TotalRows)
            //echo $pager->links();
        }
        ?>
      </div>

      
        </div>
        <div class="col-sm-1">
        </div>
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
  </body>
</html> 

Zawsze dostaję błąd: Illegal string offset 'id' w widoku.
Reply


Messages In This Thread
CI 4 pagination problem - by lukasz.bluedragon - 09-20-2020, 05:29 AM
RE: CI 4 pagination problem - by InsiteFX - 09-20-2020, 10:16 PM
RE: CI 4 pagination problem - by InsiteFX - 09-22-2020, 05:35 PM
RE: CI 4 pagination problem - by nc03061981 - 09-23-2020, 01:33 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.