doumen6605 2014-11-07 18:06
浏览 8

php命令由2个参数组成

I need to order the list as follows;

  • First the shops which are featured (featured shops have values >1 in "order_no") should be ordered according to order_no values
  • After featured shops, the regular shops ("order_no"=1) should be ordered ascending by "title" (alphabetical order)

Here are some part of the code;

const DEFAULT_ORDER_COLUMN = "title";
const DEFAULT_ORDER_BY = "asc";

public function category() {
    $orderColumn = isset( $_GET['column'] ) && in_array($_GET['column'], $this->orderColum) ? $_GET['column'] : self::DEFAULT_ORDER_COLUMN;
    $orderBy = isset( $_GET['order'] ) && in_array($_GET['order'], $this->orderBy) ? $_GET['order'] : self::DEFAULT_ORDER_BY;
    $params['total'] = $search->rowCount();
    $params['result'] = $search->fetchAll();
    template::add_content(template::load('homepage/category', $params));
}

I tried to get this issue done with this code

if ( isset( $_GET['order_no'] ) ) != 1 {
const DEFAULT_ORDER_COLUMN = "order";
const DEFAULT_ORDER_BY = "desc";
} else {
const DEFAULT_ORDER_COLUMN = "title";
const DEFAULT_ORDER_BY = "asc";
}

but did not work. What would be the solution?

  • 写回答

1条回答 默认 最新

  • douling8087 2014-11-07 18:14
    关注

    Based on your criteria, you need the following order clause:

    ORDER BY `order_no` DESC, `title`
    

    However, from your code it is not clear how you are building your sql and how the $_GET variables are related to your question.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路