douyue6520 2013-05-15 19:54
浏览 31
已采纳

在Category List组件中添加where查询

I added new parameter in Category List components,

it's a combo box Filter Type

  1. All
  2. This Month
  3. This Week
  4. Past

I was able to get the value by using the code $params->get('filter_type').

Now I got stuck on where to add a custom where query in com_contents. Is that possible?

Thanks!

  • 写回答

2条回答 默认 最新

  • dqkf49487 2013-05-15 20:09
    关注

    There's not a lot to go on here, but here's the general approach:

    $sql = 'SELECT whatever FROM com_contents';
    switch ($params->get('filter_type')) {
    case 'This Month':
      $sql .= ' WHERE EXTRACT(YEAR_MONTH FROM my_date) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE)';
      break;
    case 'This Week':
      $sql .= ' WHERE YEARWEEK(my_date) = YEARWEEK(CURRENT_DATE)';
      break;
    case 'Past':
      $sql .= ' WHERE <whatever "past" means>';
      break;
    }
    ... and then execute the query
    

    Note that there's no case for the All option; that's because it doesn't require a WHERE clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?