Chinaunix首页 | 论坛 | 博客
  • 博客访问: 341575
  • 博文数量: 89
  • 博客积分: 5152
  • 博客等级: 大校
  • 技术积分: 1155
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-25 15:12
文章分类

全部博文(89)

文章存档

2012年(1)

2011年(5)

2010年(14)

2009年(69)

我的朋友

分类: 系统运维

2009-06-26 10:55:02



We can create a sortable header using “theme_table()” function. In sortable header user can sort a column in ascending or descending order. I am using a table called “package_coupon“. This table have seven fields (coupon, operator, operand, created, expire, used and user_by). We are providing the sorting facility on four fields only (coupon, created, expire and used). Initially, the coupon field is sorted by ascending order.

Here “tablesort_sql()” function is important. This function produces the ORDER BY clause to insert in your SQL queries, assuring that the returned database table rows match the sort order chosen by the user.


function package_coupon_list() {
    $head = array(
        array('data' => t('Coupon'), 'field' => 'coupon', 'sort' => 'asc'),
        array('data' => t('Type of Discount')),
        array('data' => t('Created'), 'field' => 'created'),
        array('data' => t('Expire'), 'field' => 'expire'),
        array('data' => t('Status'), 'field' => 'used'),
        array('data' => t('Used by')),
    );
 
      $sql = "SELECT * FROM package_coupon" . tablesort_sql($head);
 
       $result = db_query($sql);
 
      while ($coupon = db_fetch_object($result)) {
        $rows[] = array(
            array('data' => _coupon_format($coupon->coupon)),
            array('data' => ($coupon->operator == '%' ? "{$coupon->operand}% discount" : "\${$coupon->operator}{$coupon->operand} discount")),
            array('data' => format_date($coupon->created, 'small')),
            array('data' => format_date($coupon->expire, 'small')),
            array('data' => $coupon->used . ' left'),
            array('data' => ($coupon->user_by == '') ? 'None' : $coupon->user_by),
        );
      }
 
    return theme_table($head, $rows);
}

阅读(1312) | 评论(0) | 转发(0) |
0

上一篇:flex 初学者网站

下一篇:在drupal中使用ajax

给主人留下些什么吧!~~