0
votes

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

3

3 Answers

4
votes

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)

1
votes

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';
}
0
votes
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{
    .
    .
.