Welcome Guest, Not a member yet? Register   Sign In
pagination doesn't work
#2

(03-21-2015, 11:39 AM)chouwech Wrote: controller:

PHP Code:
$data['result'] = $this->user_model->get_all($config['per_page'], $page);
$data['link'] = $this->pagination->create_links();

$this->template->load('users/index', array('users' => $data)); 

view:

PHP Code:
<?php foreach($users as $key => $value):?>
    <tr>
        <td><?=$value['username']; ?></td>
        <td><?=$value['email'];?></td>
        <td><?=$value['status'];?></td>
        <td><?=$value['access'];?></td>
    </tr>
<?php endforeach; ?>

I think this is the problem. When you pass 'users => $data, the array $users contains
Code:
$users['result'] => array() of users
$users['link'] => array() of links

When you say foreach ($users as $key => $value), the first time, $key will contain 'result' and $value will contain the array of users, not a single user.

It may work if instead you just pass the $data array. Then your view will have two arrays, $result and $link. Then you can go foreach ($result as $key => $value).

Well, I hope that's the answer.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply


Messages In This Thread
pagination doesn't work - by chouwech - 03-21-2015, 11:39 AM
RE: pagination doesn't work - by RobertSF - 03-21-2015, 08:34 PM
RE: pagination doesn't work - by chouwech - 03-22-2015, 01:24 AM
RE: pagination doesn't work - by RobertSF - 03-22-2015, 07:49 AM
RE: pagination doesn't work - by chouwech - 03-22-2015, 10:22 AM
RE: pagination doesn't work - by RobertSF - 03-22-2015, 11:55 AM
RE: pagination doesn't work - by chouwech - 03-22-2015, 01:18 PM
RE: pagination doesn't work - by phoenixcoded - 03-25-2015, 05:43 AM
RE: pagination doesn't work - by RobertSF - 03-25-2015, 07:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB