douzao9845 2016-02-25 22:21 采纳率: 0%
浏览 51

Drupal 7分页编号循环

function tablesort_example_page() {

print l('<button class="btn btn-default">' . t('Add New Country') . '</button>', 'mypages/countries/' . $term->tid, array('html' => TRUE));

And also i want display the above print button on the top to table....

We are going to output the results in a table with a nice header. The header gives the table the information it needs in order to make the query calls for ordering. TableSort uses the field information to know what database column to sort by.

 $header = array(

    array('data' => t('S No'), 'field' => 't.id'),
    array('data' => t('Country Name'), 'field' => 't.country_name'),
    array('data' => t('Status'), 'field' => 't.status'),
    array('data' => t('Added Date'), 'field' => 't.added_date'),
    array('data' => t('Action'), 'field' => 't.id',),
    array('data' => t('Action'), '',),
  );

Using the TableSort Extender is what tells the the query object that we are sorting.

$limit = 10;

  $query = db_select('countries', 't')->extend('TableSort')->extend('PagerDefault')->limit($limit)->orderby('country_name', ASC);
  $query->fields('t');

  Don't forget to tell the query object how to find the header information.
  $result = $query
      ->orderByHeader($header)
      ->execute(); 

this is displaying table

 $rows = array();
  $i=1;
  foreach ($result as $row) {
//print_r($row);


    // Normally we would add some nice formatting to our rows
    // but for our purpose we are simply going to add our row
    // to the array.
    $rows[] = array(
    $i,
    //$row->id,
    $row->country_name,
    $status = ($row->status == 0) ? 'Inactive' : 'Active',
    //$row->added_date,
    date('d-m-Y H:i:s', strtotime($row->added_date)),
    l('Edit', 'mypages/countries/'. $row->id),
    l('Delete', 'mypages/delete/'. $row->country_name)
    );
    $i++;
  }

here pagination not getting loop in next pages..next pages starting from 1 ..

展开全部

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部