Jesper Posted August 7, 2008 Share Posted August 7, 2008 Hey everyone, I'm coding a website and I want to show the contents of a database and sort the records by using ORDER BY in mysql and set it to DESC or ASC. Now to determine wether it has to be ASC or DESC, I store in a session the variable $_SESSION['effect_sort_dir']. I use this code: if (($_SESSION['effect_sortby_dir']=="DESC") or !(isset($_SESSION['effect_sortby_dir']))) { $effect_sortby_dir="ASC"; $_SESSION['effect_sortby_dir']="ASC"; } else if ($_SESSION['effect_sortby_dir']=="ASC") { $effect_sortby_dir="DESC"; $_SESSION['effect_sortby_dir']="DESC"; } Now I used this for the members list too (variable names had 'users' instead of 'effect'), and it worked perfectly. But for the effects, it just doesn't. Does anyone see what I'm doing wrong, or what in PHP could have caused this bug? I use session_start() before this in an included file using include(file.php). Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/ Share on other sites More sharing options...
Third_Degree Posted August 7, 2008 Share Posted August 7, 2008 I don't know what you're trying to do here but your logic seems a little strange, if the session variable is ASC, you reset it to DESC and vice versa. Are you sure this is what you are trying to do? Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/#findComment-611181 Share on other sites More sharing options...
Jesper Posted August 7, 2008 Author Share Posted August 7, 2008 Yep. So every time you click the link for sorting by name for example, it also gives you the opporunity to have the list ascending and descending . Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/#findComment-611193 Share on other sites More sharing options...
revraz Posted August 8, 2008 Share Posted August 8, 2008 echo the variable to see what it contains and you should see why it doesn't work. Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/#findComment-611263 Share on other sites More sharing options...
Jesper Posted August 8, 2008 Author Share Posted August 8, 2008 I did. Before the switching code the variable $_SESSION['effect_sortby_dir'] returns DESC and after it returns ASC. Just it doesn't change when you click the sort link again. It does 1 in 5 times tho :S. Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/#findComment-611448 Share on other sites More sharing options...
Jesper Posted August 8, 2008 Author Share Posted August 8, 2008 Does anyone know what could be the cause? For going to the new sort page I use <a href='?sort=name' name='sort_name'>Name</a> · <a href='?sort=date' name='sort_name'>Date</a> · <a href='?sort=rating' name='sort_name'>Rating</a> · <a href='?sort=category' name='sort_name'>Category</a> · <a href='?sort=downloads' name='sort_name'>Downloads</a> Link to comment https://forums.phpfreaks.com/topic/118699-php-sessions-problem/#findComment-611593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.