dpi96151 2014-08-26 11:33
浏览 8

如何排序多个元素

switch($kk)
{ 
    case 1:
        $flag=true;
        if ($month) 
        {
            echo"<pre>";   
            echo $select->where('start_date between "' . $year . '-' . $month . '-01" and "' . $year . '-' . $month . '-' . $this->daysInMonth($month, $year).'" and end_date between "' . $year . '-' . $month . '-01" and "' . $year . '-' . $month . '-' . $this->daysInMonth($month, $year).'"' );

        } 
        $select->order('start_date ASC');       
        break;

    case 2:
        $flag=true;
        if ($month) 
        {
            echo $select->where('start_date < "' . $year . '-' . $month . '-01"  and end_date between "' . $year . '-' . $month . '-01" and "' . $year . '-' . $month . '-' . $this->daysInMonth($month, $year).'"' );

        }
        $select->order('start_date ASC');
        break;

    case 3:
        $flag=true;
        if ($month) {
            echo $select->where('start_date between "' . $year . '-' . $month . '-01" and "' . $year . '-' . $month . '-' . $this->daysInMonth($month, $year).'" and end_date > "' . $year . '-' . $month . '-'.$this->daysInMonth($month, $year).'"' );
        }
        $select->order('start_date ASC');
        break;

    case 4:
        $flag=true;
        if ($month) {
            echo $select->where('start_date < "' . $year . '-' . $month . '-01" and end_date > "' . $year . '-' . $month . '-'.$this->daysInMonth($month, $year).'"' );
        }
        $select->order('start_date ASC');
        break;
}

$select->order('start_date ASC'); This statement sorts element. But it sorts according to result of query cases. I need one sort query to sort all cases result. How should I do?

  • 写回答

1条回答 默认 最新

  • douweilaton2762 2014-09-14 05:53
    关注

    You have to come out of the switch{} statement, it only executes whats in the case. Even if you put that in the default: it won't work because it works individually with cases or default. I would create an entry after the switch statement.

    Verify that your switch case executed then have another statement that does the sort to apply to all cases.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分