ビューページに2行を出力として表示したい。もう一度クリックして次のページに移動すると、次の2行などが表示されます(すべて合わせて、テーブルに8行あります)。しかし、次のコードを実行すると、ビュー ページに 8 行すべてとページネーション リンクが表示されます。私はそれが機能しない実際の理由を見つけるために一日中試みましたが、私の問題はまだ解決されていません. 関連するクエリを使用してインターネットでヘルプを検索しましたが、役に立ちませんでした。最後に、問題を説明するために私自身の言葉でここにいます。コードのほぼすべての行にコメントを付けました。ページネーションのオートロードとフォームと URL のヘルパーでライブラリをロードしています。誰かが私を助けてくれたら、本当に感謝します。前もって感謝します。
<?php
class ManageUser extends CI_Controller { // creating class for the controller
function index()
{
if($this->session->userdata('logged_in')) // checking users under session if he is already logged in
{
$this->load->model('admin/user'); // loading model . I am not using Datamapper.
$result = $this->user->view_user(); // getting response from the model and storing it to result
$total_rows = count($result); // counting number of rows countered ( its 8 in in my database )
//echo $total_rows;
if($result)
{
$data['users'] = $result;
$config['base_url'] = "http://192.168.0.102/project/index.php/admin/manageUser"; // this is the address where I am pointing the view page url
$config['total_rows'] = $total_rows; // Total numbers of rows assigned to pagination-config
$config['per_page'] = '2'; // I want to display 2 rows in 1 page
$config['uri_segment'] = '2';
$this->pagination->initialize($config); // initilizing the pagination-config
//$data['pagination'] = $this->pagination->create_links();
//$this->load->vars($data);
$this->load->view('admin/manageUser',$data); // Loading the page
}
//$this->load->view('admin/manageUser',$data);
}
else
{
redirect('admin/login'); // incase of faliured session user will be redirected to the login-page.
}
}
}
?>
次のコードは、User という名前のモデルからのものです
<?php
Class User extends CI_Model // extending the model
{
function __construct()
{
parent::__construct();
}
function view_user() // function which is loaded from controller
{
$query = $this -> db -> get('users'); //query to fetch all the information from the database
return $query->result(); // returning result to the Controller.
}
}
?>
最後に、これはコンテンツを表示するために使用しているビュー ページです。
<!-- This is the view page -->
<?php if(isset($users)) { ?> <!-- Checking if user is set -->
<?php foreach($users as $user) { ?> <!-- running in a loop to accept all the value from the database and display it row wise -->
<td><?php echo $user -> us_display_name; ?></td> <!-- Displaying name -->
<td><?php echo $user -> us_first_name . " " . $user -> us_last_name; ?></td> <!-- Displaying first name and last name together -->
<td><?php echo $user -> us_email_id; ?></td> <!-- Displaying email-ID -->
<?php } } else { ?>
<tr> <td>No records found!</td>
<?php } ?>
<?php echo $this->pagination->create_links(); ?>