I have three links each with an 'ORDER BY' option. I used this if structure to change the $sql and order it in the right way. I don't get any errors on my order pages but on the main, unsorted page I get "Notice: Undefined index: sort" on each line where I use sort (3 times).
I googled and tried a few of the possible solutions on stackoverflow but nothing helped so far. I'm sorry if this is a basic question but I'm quite new to php so I'm a bit confused as to why I'm getting this error.
<?php
//Query for speaker information
$sqlOverzichtSprekers = "SELECT idsprekers, voornaam, naam, afbeelding,
bio, likecounter FROM sprekers";
//Sql ORDER BY
if ($_GET['sort'] == 'alpha')
{
$sqlOverzichtSprekers .= " ORDER BY voornaam DESC";
}
elseif ($_GET['sort'] == 'popular')
{
$sqlOverzichtSprekers .= " ORDER BY idsprekers";
}
elseif ($_GET['sort'] == 'likes')
{
$sqlOverzichtSprekers .= " ORDER BY likecounter DESC";
}
//Query for speaker
if(!$resOverzichtSprekers = $mysqli->query($sqlOverzichtSprekers)){
echo "Oeps, een query foutje op DB voor opzoeken sprekers";
print("<p>Error: " . $mysqli->error . "</p>");
exit();
}
?>
The order by/sort pages work fine without any errors, only the main unsorted page has the following error: Notice: Undefined index: sort.