drupal 连表查询+分页

$query = db_select('Table','t');
     $query->join('Table_A','a','on条件);
     $query->join('Table_B','b','on条件'); 
    
     $objects=$query->extend('PagerDefault')//重要,extend('PagerDefault')实现分页
     ->fields('t', array( 'colname_1','colname_2')) 
     ->fields('b', array( 'colname_1','colname_2')) 
      ->fields('b', array( 'colname_1','colname_2')) 
->condition('t.status',1) ->condition('a.status',1)
->orderBy('n.created','DESC') ->limit(1) -> execute() ;

$output="";
$rows = array();

$title_length=25;

foreach ($objects as $key => $object)
{

$row = array();

$title="";

if (strlen($object -> filename)>$title_length) {

   $title= drupal_substr($object -> filename,0,50).'...' ;//最多显示12个字
}
else { $title= $object -> filename ;//最多显示12个字 }
$url_head='http://'.$_SERVER['HTTP_HOST'].'/drupal755/sites/default/files/';

$url=$url_head.ltrim($object->uri,'public://');

$row['title']=l($object -> filename,$url);

$row['created']=date('Y-m-d',$object->created); $rows[] = $row;
}

$results=$rows;

$output .= theme('table', array('rows' => $rows));

$output .= theme('pager'); return $output;

 

posted @ 2016-12-15 09:43  jiafeng  阅读(671)  评论(0编辑  收藏  举报