mysql - CodeIgniter 分页多表

标签 mysql codeigniter pagination

我有关于数据库和分页的学校作业,任务是在选定的表上显示数据。

例如,当我们选择“table_data1”时,浏览器将显示“table_data1”中的数据并将其显示为分页页面,

我找到了一个关于分页的教程,然后我修改了代码,结果是,当我选择下一页时,它显示了第一页记录的5条数据,但是下一页的分页不显示。

这是我的模型,$tabel 是选择运行查询的 table_data$

class Page_model  extends CI_Model{

function join_data($limit, $start,$table)
{

    $this->db->select('*');
    $this->db->limit($limit, $start);
    $this->db->from('tbl_param');
    $this->db->join('tbl_data' . $table, 'tbl_data' . $table .'.id  =  tbl_param.child_id', 'left');
    $this->db->join('table_limit' . $table, 'table_limit' . $table .'.id  =  tbl_param.child_id', 'left');
    $query4 = $this->db->get();
    $this->db->limit($limit, $start);
    return $query4->result();
}
}

这是我的 Controller ,$tabel 用于选择要显示的 table_data$

class Page extends CI_Controller{

function page($table)
    {
        $this->load->library('pagination'); 
        $config['base_url'] = base_url().'index.php/page/'.$table.'/';            
        $config['total_rows'] = 20;
        $config['per_page'] = 5;
        $this->pagination->initialize($config);
       
        $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
       
        $data['table'] = $this->page_model->join_data($config["per_page"], $page,$table);
        $data['links'] = $this->pagination->create_links();
        $this->load->view('v_page', $data);
    }
}

和 View

 <?php foreach($table as $tables){ ?>
        <tr>
            <td><?php echo $tables->id;?></td>
            <td><?php echo $tables->param;?></td>
            <td><?php echo $tables->data;?></td>
            <td><?php echo $tables->alarm;?></td>
        </tr>
        <?php } 
        echo $links;
        ?>

我希望有人帮助我或解释一下,我该怎么办?

最佳答案

我认为你的问题出在你的 $config['base_url']$page

你的$config['base_url']应该是base_url().'index.php/page/page/'.$table;

注意第二个 page,您需要在 page Controller 内调用的方法。

你的$page应该是$page = $this->uri->segment(4);

关于mysql - CodeIgniter 分页多表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300210/

相关文章:

mysql - 用名称替换 GROUP_CONCAT 列中的 ID

mysql - Ejabberd 中 MySQL 和 Mnesia 哪个更好?

backup - windows上的mysql自动备份

php - 使用 Codeigniter 处理 ajax 响应

azure - 如何在/providers/Microsoft.Compute/virtualMachines REST API中的azure分页中使用nextLink属性

performance - 为什么分页如此耗费资源?

Mysql - 复杂的查询给我带来了问题

php - 根据MySQL数据库中的积分获取用户排名

php - 如何根据我在 codeigniter session 中拥有的电子邮件返回数据?

css - 如何将分页对齐到屏幕的底部中心?