PHP GET 没有改变?
我构建了一个开关来更改升序和降序排序的顺序, $_GET['sense'] 是它应该排序的方式,当它是 ASC 时,下一次 $sorting 应该是 DESC (我将其传递给函数将其添加到 url)。然而,它从 DESC 到 ASC 永远不会改变。我不明白为什么。
重要的语句是 if($sorting) :
我想说如果变量是 ASC,那么它应该是 DESC,如果它是其他任何东西(希望是 DESC)那么它应该再次是 ASC。但这似乎不起作用。
if(isset($_GET['column']) && isset($_GET['sense'])){
$sorting = antiInjectie($_GET['sense']);
$temp = antiInjectie($_GET['column']);
if($sorting = "ASC"){
$sorting = "DESC";
}else{
$sorting = "ASC";
}
if(tableNameMatcher($temp)){
$order = $temp;
}
}else{
$order = "naam,voornaam";
$sorting = "ASC";
}
注意 第二个 else 语句适用于没有给出任何内容的情况
I built a switch to change the order of ascending and descending a sort, the $_GET['sense'] is the way it should be sorted, when it is ASC, the next time $sorting should be DESC ( I pass this to a function to add this to a url). However it never changes from DESC to ASC. I can't figure out why.
The important statement is the if($sorting) :
I want to say if the variable is ASC it should be DESC, if it is anything else (DESC hopefully) then it should be ASC again. But this doesn't seem to work.
if(isset($_GET['column']) && isset($_GET['sense'])){
$sorting = antiInjectie($_GET['sense']);
$temp = antiInjectie($_GET['column']);
if($sorting = "ASC"){
$sorting = "DESC";
}else{
$sorting = "ASC";
}
if(tableNameMatcher($temp)){
$order = $temp;
}
}else{
$order = "naam,voornaam";
$sorting = "ASC";
}
note The second else statement is for when there isn't anything given
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
if($sorting == "ASC"){
而不是if($sorting = "ASC"){
作为 if 子句(您忘记了=
)解释:在你的 if 子句中,你总是将
$sorting
设置为 'ASC' (你不进行比较)use
if($sorting == "ASC"){
instead ofif($sorting = "ASC"){
as your if-clause (you forgot a=
)explanation: in your if-clause you always set
$sorting
with 'ASC' (you do no comparision)您可以稍微简化此代码并同时解决您的问题:
You can streamline this code a bit and solve your issue at the same time:
现在你必须这样做
NOW YOU HAVE TO DO THIS