我认为从数据库获取所有数据,我不会在我的代码中进行分页。
我会尝试这种方式在我的网站上进行分页,但它不会显示分页。
视图如下: -
<ol class="timeline2 clear">
<li class="spine">
</li>
<?php
$counter=0;
//print_r($response);
foreach ($response as $row) {
if($counter % 2 == 0){$class= "left";} else $class="right";
?>
<li class="<?=$class ?>">
<i class="pointer"></i>
<div class="unit">
<!-- Story -->
<div class="storyUnit">
<div class="imageUnit">
<? if (empty($row->pic)) { ?>
<a href="#"><img width="32" height="32" alt="" src="images/nopic.png"></a>
<? } else { ?>
<a href="#"><img width="32" height="32" alt="" src="uploads/<?php echo $row->pic; ?>"></a>
<div id="delpost" style="float:left">
<a href="./myaccount/deletePostInProfile/<?=$row->ev_id;?>" id="deletepost">X</a>
</div>
<? } ?>
<div class="imageUnit-content">
<h4><a href="./myaccount/profile/<?php echo $row->id; ?>"><?php echo $row->fullname; ?></a></h4>
<p><?php echo $row->ev_date ?></p>
</div>
</div>
<p> <?php echo $row->ev_text; ?><br />
<? if (!empty($row->ev_pic)) { ?>
<img src="uploads/<?php echo $row->ev_pic ?>" width="250" height="250"</p>
<? } ?></p>
</div>
<!-- / Story -->
<!-- Units -->
<ol class="storyActions" id="storyActions<?php echo $row->ev_id; ?>">
<?
$selectComment = mysql_query("select * from comment,users where
comment.co_postid = '".$row->ev_id."'
and comment.co_userid = users.id order by co_date DESC ");
while($rows=mysql_fetch_array($selectComment)){
?>
<div id="resultcomment<?php echo $row->ev_id; ?>"></div>
<div id="resultcomment" style="border-top:1px solid #fff;">
<a href="./myaccount/profile/<?php echo $rows['id']; ?>">
<img src="uploads/<?=$rows["pic"];?>" width="32" height="32" class="rightc" />
</a>
<b><a href="./myaccount/profile/<?php echo $rows['id']; ?>"><?=$rows["fullname"]; ?></a></b>
<span> </span>
<span><?=$rows["co_comment"]; ?></span>
<br />
<span class="commentdate"><?=$rows["co_date"]; ?></span></br></div>
<? } ?>
<form action="" method="post" accept-charset="utf-8">
<input type="text" class="commentprofile" id="comment<?php echo $row->ev_id; ?>" name="comment<?php echo $row->ev_id; ?>" size="41" />
<input type="hidden" id="postid<?php echo $row->ev_id; ?>" name="postid<?php echo $row->ev_id; ?>" size="41" value="<?php echo $row->ev_id; ?>" />
<button type="button" id="submit" onclick="add_comment(<?php echo $row->ev_id; ?>)">ارسل</button>
</form>
</ol>
<!-- / Units -->
</div>
</li>
<?php $counter++; } ?>
<div class="clear"></div>
</ol>
<? } ?>
<div>
<?php echo $this->pagination->create_links(); ?>
</div>
和我的控制员: -
public function profile($user_id) {
$check = new User();
$ex = $check->where('id',$user_id)->count();
if( $ex == 0){ redirect('./home'); }
else {
$user = new User($user_id);
/************************************** Post *******************************************************************/
$this->load->model('blog');
if(isset($_POST['post'])){
// Config setup
$config['base_url'] = base_url().'/myaccount/profile/'.$user_id.'/';
$config['total_rows'] = 20;
$config['per_page'] = 10;
$config['num_links'] = 5;
// Initialize
$this->pagination->initialize($config);
if(strlen($_FILES['inputUpProfile']['name']) > 0)
{
$pic = $this->do_upload('inputUpProfile');
if ($this->input->post('post') == ''){$type="image";} else {$type="image-with-text";}
}
else {$pic = ""; $type = "text"; }
$result = $this->blog->addPost($_SESSION['user_id'], $type , $this->input->post('post'),$pic);
}
if(isset($_SESSION['user_id']) || !empty($_SESSION['user_id'])){
$result = $this->blog->getPost($user_id, 0 , 10);
$this->template->build("profile" , array("response"=>$result));
}
else{
$this->template->build('registration_view',$this->data);
}
$this->data['user'] = $user;
$this->data['errors'] = $this->errors;
$this->template->set_layout('myaccount');
$this->template->build('profile',$this->data);
}
}
模块: -
function getPost($user_id, $from, $to) {
$query = $this->db->query("SELECT * FROM events,users
where events.ev_user_id = '".$user_id."'
and events.ev_user_id = users.id
order by events.ev_date DESC limit 10");
return $query->result();
}
为什么分页不会显示在我的网站上?
答案 0 :(得分:0)
初始化分页后在控制器中:
$this->data['pagination_links'] = $this->pagination->create_links();
然后在您希望显示分页链接的视图中:
echo $pagination_links;
您试图在视图中回显它们而不先在控制器中创建它们。文档中的示例有点不好,因为它只是让您在控制器本身中回显它们。