php - CodeIgniter. Allowed memory size error and pagination ← (PHP, CodeIgniter)

one text

Solution:

Your codeigniter code is storing the entire list in array first. After that you are trying to build the screen. Perhaps you can start with a SQL join and use limit in that join to restrict the number of rows. Also, send your script page number for pagination.

<?php

$current = $_GET['page'];
$rowCount = $_GET['length'];

$sql = "select * from model m
inner join brand b
on m.vehicle_brand_id = b.id
limit ".($current - 1)*($rowCount).",".$rowCount;

$query = $this->db->query($sql);
    $content['tableList'] = $query->result();

In this way, you will not pull entire data, which eventually causes memory exhaustion error.

Source