PHP GET 没有改变?

发布于 2024-11-26 09:47:36 字数 814 浏览 0 评论 0原文

我构建了一个开关来更改升序和降序排序的顺序, $_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一张白纸 2024-12-03 09:47:36

使用 if($sorting == "ASC"){ 而不是 if($sorting = "ASC"){ 作为 if 子句(您忘记了 =

解释:在你的 if 子句中,你总是将 $sorting 设置为 'ASC' (你不进行比较)

use if($sorting == "ASC"){ instead of if($sorting = "ASC"){ as your if-clause (you forgot a =)

explanation: in your if-clause you always set $sorting with 'ASC' (you do no comparision)

无风消散 2024-12-03 09:47:36

您可以稍微简化此代码并同时解决您的问题:

if(isset($_GET['column']) && isset($_GET['sense']))
{
    $sorting = (antiInjectie($_GET['sense']) == 'ASC') ? 'DESC' : 'ASC';
    $temp = antiInjectie($_GET['column']);
    $order = (tableNameMatcher($temp)) ? $temp : '';
}
else
{
    $order = 'naam,voornaam';
    $sorting = 'ASC';
}

You can streamline this code a bit and solve your issue at the same time:

if(isset($_GET['column']) && isset($_GET['sense']))
{
    $sorting = (antiInjectie($_GET['sense']) == 'ASC') ? 'DESC' : 'ASC';
    $temp = antiInjectie($_GET['column']);
    $order = (tableNameMatcher($temp)) ? $temp : '';
}
else
{
    $order = 'naam,voornaam';
    $sorting = 'ASC';
}
柠檬 2024-12-03 09:47:36
if($sorting = "ASC"){ // here you store "ASC" into $sorting not comparing it
    $sorting = "DESC";
}else{
    $sorting = "ASC";
}

现在你必须这样做

if($sorting == "ASC"){
    $sorting = "DESC";
}else{
    .
    .
.
if($sorting = "ASC"){ // here you store "ASC" into $sorting not comparing it
    $sorting = "DESC";
}else{
    $sorting = "ASC";
}

NOW YOU HAVE TO DO THIS

if($sorting == "ASC"){
    $sorting = "DESC";
}else{
    .
    .
.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文