Drupal 函数实现分页机制

Drupal 函数实现分页机制


php 代码:

echo "<div >";
$query = db_select('node', 'n')->extend('PagerDefault'); 
$query->addField('n', 'nid'); 
$query->addField('n', 'title'); 
$query->condition('n.status', 1)->limit(5);  
$query->condition('n.type','article')->limit(5);
$query->condition('n.nid',$aid)->limit(5);
$query->orderBy('nid', 'DESC'); 
if ($fetch = $query->execute()->fetchAll()) { 
  $rows = array(); 
  foreach ($fetch as $obj) { 
    $rows[] = array(l($u.'  *_*  <<'.$obj->title.' >> ------详细信息查看,单击此处', 'node/' . $obj->nid)); 
    $u++;
  } 
 }
 echo theme('table',  array('header' => $header, 'rows' => $rows)); 
  echo '<hr>'; 
  echo theme('pager'); 
  echo "</div>"




说明。直接调用方法就可以了。

获取本地时间地址代码:

function GetIP(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}
$ip = GetIP();
echo '日期:';
echo date('Y-m-d ',time()).'</br>';
echo '本机地址:'.$ip;
$str = "</br><p>同学们,网络安全实验室的网站开始试运行啦!</p><hr/><h3>快来关注我们吧!</h3>";
echo $str;


你可能感兴趣的:(函数,分页,机制,drupal)