-1
出力としてビューページに2行を表示したいのですが、次のページに移動するには、次のページに移動すると、2つの次の行が表示されますしかし、私が次のコードを実行すると、ページングリンクと共にビューページの8行が表示されます。 実際の理由を見つけるために一日中試してみましたが、まだ問題は解決していません。関連するクエリを使用してインターネット上のヘルプを検索しましたが、それは役に立たなかったのですFinalyy私はここで自分の言葉で説明しています 私のコードのほとんどすべての行にコメントしました。フォームとURLのヘルパー。 誰かが私を助けてくれたら本当に感謝します。ありがとうございます。ページ番号がcodeigniterで機能していません:(
<?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.
}
}
}
?>
次のコードは、私のモデルという名前のユーザー
<?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(); ?>
を制限する必要があるモデルで.... –
: あなたのコントローラは、このようなものでなければなりませんそれと一緒に。しかし、それは動作しません。以下のコードを確認してください。 <?php if(!define( 'BASEPATH'))exit( 'スクリプトの直接アクセスは許可されていません'); 関数インデックス($ offset = 0) { \t \t $ this-> load-> model( 'user'); \t \t $ this-> load-> library( 'pagination'); $ user_list =新しいユーザー(); $ total_rows = $ user_list-> count(); // $ student_list-> order_by( 'name');$ data ['user_list'] = $ user_list-> get(5、$ offset) - >すべて; –
あなたはどんなエラーを受けていますか –