$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;
不要问我底层的实现原理,我也是不知道呢,暂时记一下~
效果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMMAAAApCAIAAAAHwgoZAAAEM0lEQVR4nO2YwWviShzH81/k2OMee/TgQfbUo0ePPT28PJApiOTiQR7k4KF7qxeRZaHyvOQwDIEQ3BVRa0HDFmlgQ4mUQC24m7rFBILw24Np1T7bh3Fku7u/D57UmXyT+fD7zUQABOGB8LMDIL8JaBLCBzQJ4QOahPABTUL4gCYhfECTED6gSQgf0CSED2gSwgc0CeEDmoTwAU1C+IAmIXxAkxA+oEkIH9AkhA9oEsIHNAnhww5NGv77Vzx+xMbRRk9NvXGQpQKhe5J+Yk6jzeKbZ4cSFQjdyzfU0SzaJFtz73pc5xv1kqTZ+ekxVtmNSd+/sH8O38bj0U0y2/tS4+MkAJi5/WaM1NXJ5pNMBmmiVRwfIHC7jX3pzIyUZTuuT/JUvuA6ZRSTdhBjlV2YNHgXj8ffHh0dbWHSCrfVwtZPIbjMEU35un2YTbFk8hpM2kGMVXZi0oe/P/THc6G4mORU8lTeqp74NtX2isZNhKGjXpLUT8JWy1K1oR+GMjIFJhIqZrUT8x4A/G5dlJodDwDAv2jGpEbHG1dlKhAq8F3FhUkzt9+et2+BsIPSZxsAYGrUtDeECoQelAw7AIDdxFhlh/skbiZZ7ZjUNrYYL0tsj7Bc91uU0aNektBk7doFAKeXIuzYmlc4luuOIfxSrTgAMP1YorGy5XuDDGHyxTS8+rr1881motizo93Qo0kT45BoVScAmPnOeZJQ2QQwm2L+zAwA4F4t0aQ+fiEGgFMpMNn03ZYeK1t+tDwA8AuY5FmyxGRzm3sEAIDJZS7aPKNectEWx1WZyhfgd+tCYeGBragJxQEA8AYZwhJ5urQqzy3htFNmKT3S01nf3R72AFZ7n6jyp6HtBUu/Pt/drHZMahrBWCnSTDfiyQZevUm31SJN6bdc8hinTHx/tfGwlWULTbrRtXmzWHzK1vwfZo0JK+eD55fQG2SymjLaONFyd/NHV9Va+7ikJ/JMDC8U3PTP0gUmErqXr1fMl0ojAAD4xnsWK1vuqJckepSTDQC8apO+WnKBHepR9jZrMU5ZWDk2Yp1JbksX3n121/05RdTDItv//5o0NynSyj1GstoxosqfLjv22PWcp+eS4JuhaGK4MfhjTZoM0tmtq5FzfkDq6mQGADCx5PyWBQAeTZp3sXCfNLmuFGm6dQdwW5VpSr+dd+Rcf14MhscSzfX/+ypr2imzdOsuyn09RLrRNUE+twOA4M5QNJHQTNd3W3VRPreDWfjuo3BuvxTjd+9utqI+aR/JKFuKxdFmqc5vyFqTYHF2E7JqWhn6MDNOmfiwifb7jX2p0fEAwDdOVZHQJ9L4ZjMR7Sy5HMkbnshhhox+pZRoQnEA7o2aHstSgdA3hcf3setj/Bo7buSPAk1C+IAmIXxAkxA+oEkIH9AkhA9oEsIHNAnhA5qE8AFNQviAJiF8+AG+Cc4Slgj67AAAAABJRU5ErkJggg==" alt="" />
很纳闷,单击2,3····页时,代码是怎么知道该怎么查询的?是把查询语句缓存了吗?