I decided to try to make a grid panel, so that people could choose how many records they displayed, but, again, there were some difficulties.

To save the choice that the user made, I use cookies. If the user navigates through the page: videos? Section = recent & grid = big, then his choice is recorded in the cookie, I do it like this, check if the grid variable is empty, and change it with the switch.

if(isset($_GET['grid'])) { $grid = $_GET['grid']; switch($grid) { case 'low': $grid4 = 'active'; SwitchGrid($connect,$s_id,'&grid=low'); setcookie("grid", 'low', time()+3600, '/'); $cookie = $_COOKIE['grid']; break; case 'medium': $grid3 = 'active'; SwitchGrid($connect,$s_id,'&grid=medium'); setcookie("grid", 'medium', time()+3600, '/'); $cookie = $_COOKIE['grid']; break; case 'big': $grid2 = 'active'; SwitchGrid($connect,$s_id,'&grid=big'); setcookie("grid", 'big', time()+3600, '/'); $cookie = $_COOKIE['grid']; } } 

Everything is ok. Everything is recorded in a cookie, but now if I go to the menu, say, first by the link videos? Section = recent & grid = big , and then by the link videos? Section = recent & grid = low , then the other links that contain $ cookie variable will not matter the current low, but big, that is, it is not updated when moving to another page, but only if you update the page manually .. I don’t know how to solve it except for JS, but I don’t I know, unfortunately. Can you help?: D

If I didn’t explain very clearly, you can check it yourself here, if the links are not prohibited, of course, the grid panel is to the right, and you need to look at the links Recent, Popular, Following, Suggestion.

http://rrcf.tk/videos?section=recent&grid=big

ps - sorry for the multi-bookmark.

    1 answer 1

    You probably have an erroneous attempt somewhere to use the newly received cookie to generate links, which indicates the previous grid mode. And you need a current one.

     if (isset($_GET['grid'])) { // получить grid из параметра запроса $grid = $_GET['grid']; } else if (isset($_COOKIE['grid'])) { // или из cookie $grid = $_COOKIE['grid'] } else { // или по умолчанию $grid = 'medium'; } // в таком порядке setcookie("grid", $grid, time()+3600, '/'); // запомнить выбор в cookie сразу же switch ($grid) { case 'low': $grid4 = 'active'; SwitchGrid($connect,$s_id,'&grid=low'); break; case 'medium': $grid3 = 'active'; SwitchGrid($connect,$s_id,'&grid=medium'); break; case 'big': $grid2 = 'active'; SwitchGrid($connect,$s_id,'&grid=big'); } 

    Thus, in the links Recent, Popular, Following, Suggestion you can get rid of the grid parameter at all (otherwise why do you need a cookie in general?) Or focus on the value of $grid .

    PHP do not know. I do not know what value will be in $_COOKIE['grid'] after setcookie() . Most likely it will remain from the browser. So remove the use of $_COOKIE['grid'] in SwitchGrid() and in the code after switch ($grid) {} from wherever links are formed.

    • Everything works, thanks a lot! And a special thank you so much for the clarification! - Alexandra Kott