2012-03-08 35 views
1

我有一個數據庫中的數據表,我希望它有一個傳呼機,我有其他網站的示例(buildamodule.com)的所有代碼,並且我的表得到的呈現,但它不產生尋呼機,雖然我有更多的行,那麼限制:Drupal 7主題(''pager') - >表得到的呈現,但沒有尋呼機?

enter image description here

功能:

function get_loyaltycodes(){ 
$headers = array(
    array(
     'data' => t('Code') 
    ), 
    array(
     'data' => t('Info') 
    ), 
    array(
     'data' => t('Points') 
    ), 
    array(
     'data' => t('Consumed by') 
    ), 
); 
$limit = variable_get('codes_per_page',5); 
$query = db_select('loyalty_codes','lc'); 
$query -> fields('lc',array('code','info','points','uid')) 
     -> orderBy('lc.info','ASC') 
     -> extend('PagerDefault') 
     -> limit($limit); 


//to see all codes for a certain amount of points, just append the number of points to the URL  
$arg = arg(2); 
if($arg != '' && is_numeric($arg)) 
{ 
    $query->condition('points', $arg); 
} 

// Fetch the result set. 
$result = $query->execute(); 
$rows = array(); 
    // Loop through each item and add to the $rows array. 
    foreach ($result as $row) { 
    $rows[] = array(
     $row->code, 
     $row->info, 
     $row->points, 
     $row->uid, 
    ); 
    } 

    // Format output. 
    $output = theme('table', array('header' => $headers, 'rows' => $rows)) . theme('pager'); 

    return $output; 

在$限制變量設置爲5的設置形式,它是5數據庫也是如此。

任何人誰不知道尋呼機爲什麼不顯示?也許在格式化輸出的東西?

幫助非常感謝!

回答

5

顯然我無法登錄正確的認識,因爲我在防火牆後面,反正我似乎有固定的,愚蠢的錯誤,但:

‘->extend(‘PagerDefault’)擴展查詢必須是在第一個函數菊花鏈。如果沒有錯誤,但該函數似乎不被調用。

$query = db_select('loyalty_codes','lc') 
     ->extend('PagerDefault') 
     -> fields('lc',array('code','info','points','uid')) 
     -> orderBy('lc.info','ASC') 
     -> limit(5);//$limit); 
+1

它不需要是鏈中的第一個函數(這也是我以前的想法)。看到[這個問題]接受的答案(http://stackoverflow.com/questions/7637279/how-do-i-get-pagerdefault-queries-to-work-correctly-with-drupal-7)清除它很好 – Clive 2012-03-08 09:43:35