HDFilmMaker2112 Posted June 5, 2011 Share Posted June 5, 2011 I need a way to store the settings for a specific category that user is viewing. Say they click into category "A", and choose Sort By: Name and Products per Page: 24 and then click into category "C", and choose Sort By: Price and Products per Page: 48. Then click back into category "A", I want their initial settings choices of Sort By: Name and Products per Page: 24 to come back up. I also want to keep this in the URL as best as possible so they can bookmark it. How do I do this? if(isset($_GET['cat'])){ $cat=$_GET['cat']; $cat=str_replace("-"," ", $cat); session_start(); if(isset($_GET['num_products'])){ $num_products_per_page=$_GET['num_products']; $num_products_per_page = stripslashes($num_products_per_page); $num_products_per_page = mysql_real_escape_string($num_products_per_page); } else{ $num_products_per_page="20"; } $num_products=''; if(isset($_GET['sort_by'])){ $sort_by_selected=$_GET['sort_by']; $sort_by_selected = stripslashes($sort_by_selected); $sort_by_selected = mysql_real_escape_string($sort_by_selected); } else{ $sort_by_selected="product_id"; } $sort_by=''; } Quote Link to comment https://forums.phpfreaks.com/topic/238435-storing-product-page-view-settings-for-specific-category/ Share on other sites More sharing options...
Psycho Posted June 5, 2011 Share Posted June 5, 2011 If you want the options to be remembered you will need to store them somewhere. The most logical options would be in cookies or in session data. You can use cookies to have the options persists across sessions or use the session variable to just remember them for the session. You can then use the cookie/session value to implement the appropriate option on each page load. It is an easier solution since you don't have to modify all the links on your pages. So, for the first part to remember the options. When the user selects an option you will detect in on the next page load. Just store that option in the session/cookie as a sub-element of a category element. So, in your example, if the user selected "category "A", and choose Sort By: Name and Products per Page: 24", then you would store the options like this: if(isset($_GET['num_products'])){ $num_products_per_page=$_GET['num_products']; $cookie[$cat]['num_products_per_page'] = $num_products_per_page; //..... if(isset($_GET['sort_by'])){ $sort_by_selected=$_GET['sort_by']; $cookie[$cat]['sort_by_selected'] = $sort_by_selected; Now, if you really want to include the options int eh URLs then you will need to add some logic anywhere that you provide a link to another page where you want the options "remembered". I would suggest creating a function to create the URLs. For example, you create a function that takes the base URL and the category. The function then uses the category to see if there are remembered options for that category and append them to the base URL. Quote Link to comment https://forums.phpfreaks.com/topic/238435-storing-product-page-view-settings-for-specific-category/#findComment-1225371 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 5, 2011 Author Share Posted June 5, 2011 Works perfectly. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/238435-storing-product-page-view-settings-for-specific-category/#findComment-1225386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.