drupal7 分页
$output = ""; $query = db_select('feedback','f')->extend('PagerDefault');//->extend('PagerDefault')不能少哦 $query -> fields('f'); $query->orderBy('f.created','DESC'); $query -> limit(5);//每页记录数量 $objects = $query -> execute() -> fetchAll(); $type=1; $fb_limit = db_query("SELECT * FROM {feedback_config} WHERE type = :type", array(':type'=>$type))->fetch(); $rows = array(); foreach ($objects as $key => $object) { $row = array(); $row['fid'] = $object -> fid ; //标题 $row['title'] = $object->title <= $fb_limit->num_title_topshow? $object -> title: drupal_substr($object -> title,0,$fb_limit->num_title_topshow).'...' ; $row['full_title']=$object->title; //标题 $row['body'] = $object -> body<=$fb_limit->num_body_topshow? $object -> body: drupal_substr($object -> body, 0,$fb_limit->num_body_topshow).'...' ; $row['created']=date('Y-m-d H:i:s',$object->created); $rows[] = $row; } $output .= theme('hellozjf_top', array('rows' => $rows)); $output .= theme('pager');//drupal7自带分页功能 return $output;
不要问我底层的实现原理,我也是不知道呢,暂时记一下~
效果:
很纳闷,单击2,3····页时,代码是怎么知道该怎么查询的?是把查询语句缓存了吗?