PHP Switch 语句
switch ($sort) {
case 'abc':
$order_by = 'subject ASC';
break;
case 'fn':
$order_by = 'u.username ASC';
break;
case 'rd':
$order_by = 'p.posted_on DESC';
break;
default:
$order_by = 'p.posted_on DESC';
$sort = 'rd';
break;
}
我想稍微修改一下这段代码,我只是不太确定该怎么做。我很确定我可以用 if else if else if 来做到这一点,但我假设更改此开关会非常简单,但我又不确定。
无论如何,这就是我想要做的,让我们以“case 'abc”为例:例如
我想要
case 'abc':
$order_by = 'subject DESC';
break;
IF
case 'abc':
$order_by = 'subject ASC';
break;
这样,当您对记录进行排序时,如果排序已经使用 ASC,它将立即切换到 DESC我的排序按钮只能以一种方式工作。
泰
switch ($sort) {
case 'abc':
$order_by = 'subject ASC';
break;
case 'fn':
$order_by = 'u.username ASC';
break;
case 'rd':
$order_by = 'p.posted_on DESC';
break;
default:
$order_by = 'p.posted_on DESC';
$sort = 'rd';
break;
}
I want to modify this little piece of code slightly I'm just not quite sure how to do it. Im pretty sure I could do it with an if else if else if, but Im assuming changing this switch would be pretty simple, but then again I'm not sure.
Anyway this is what Im trying to do, lets take the `case 'abc': for example
I want
case 'abc':
$order_by = 'subject DESC';
break;
IF
case 'abc':
$order_by = 'subject ASC';
break;
So that way, when you are sorting through records, if the sort is already using ASC, it will switch to DESC, right now my sort buttons only work one way.
TY
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会设置一个切换变量:
或者,也许是更简洁的方式:
I would set a toggle variable:
Or, maybe a more succinct way: