1

データベースからのデータを含むテーブルがあり、ページャーが必要です。他のサイトの例 (buildamodule.com の) のすべてのコードがあり、テーブルはレンダリングされますが、生成されません。ページャー、制限よりも多くの行がありますが:

ここに画像の説明を入力

関数:

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;

$limit 変数は設定フォームで 5 に設定されており、データベースでも 5 です。

ページャーが表示されない理由を知っている人はいますか? おそらく出力のフォーマットに何か?

助けていただければ幸いです。

4

1 に答える 1

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);
于 2012-03-08T08:51:19.687 に答える