user190078
user190078

Reputation: 1

Set multiple variables via $_GET from URL

I have a table that can be sorted by any column using GET. I'm trying to make a second variable that determines sort order also using get. My understanding is that I could make the address as follows:

mypage.php?sortorder=1&sorttype=up

Using this as my code:

if (isset($_GET['sortorder'])) {
    $sortorder = $_GET['sortorder'];
}
if (isset($_GET['sorttype'])) {
    $sorttype = $_GET['sorttype'];
}
if ($sorttype = 'up') {
    $sortby = SORT_ASC;
}
else {
    $sortby = SORT_DESC;
}

My question is, what am I doing wrong? The GET for sort type is ignored, selecting the 'else' value every time.

Upvotes: 0

Views: 178

Answers (1)

Peter
Peter

Reputation: 31741

if ($sorttype = 'up') should be if ($sorttype == 'up') (note the double equals sign).

Upvotes: 1

Related Questions