douzao9845 2016-02-26 06: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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行