I have two requests to my server. The first one gets categories and the output to URL is something like this: doomain.com?category=1. The second request is meant for sorting the data in that specific category. This request outputs something like: domain.com?sort-by=name. What I need is something like this: domain.com?category=1&sort-by=name. I cant do this at the moment because whenever I submit a form it starts a new request. I need to remember the previous request and then add a new request to it with on "&" sign. Or if there is no previous request then do it normally with "?" sign. How can I achieve such thing?
How do I use your method with forms ? With many forms ? Please elaborate.
I dont think I can use your method, because your method would leave url domain.com?name&1. I have nothing to do with those. Could it be that your method needs url rewrite with .htaccess. If so, then its not really suitable because I dont know much about htaccess.
I am sorry, but I still dont get this. I mean, how do I set those variables? If I make a request then all the parts should be in the $_REQUEST. I cant just set arrays. I have to set $_REQUEST['get_page'], $_REQUEST['feature-cat'] and $_REQUEST['sort-by'] all at the same time. BUT they dont have to be set on the same time. If the users has not used sorting then sort0by would not be set. I mean I could make tens of IF statements but thats just brutal and impractical. I almost get your method but I need to know how do you set the array keys. You would still have to make a request to set them, dont you ? And if you do then you already gave an awway of variables called $_REQUEST ?
Yes, that is exactly what I need. But will it still work when the category is not set ? That is when the user hasn't specified what category he wants to see so all the products in the category will be shown instead. That would mean the featrue-cat is not set and therefor the sort-by part can not be with & but with ?.
I do have dropdown menu and it submits itself when it's value is changed. And another thing. Another quick question. Is there some some approved method that is being used to solve these kind of problems. I mean big CMS has to have some way to handle this situations. Maybe there is some kind of a term that I can google for and learn more about it. I feel like this a very important part of web developement and I need to master it.
Thank you for your reply, it was already very helpful.
The category is not set on page load I take it. So in that case all are shown. You could set category_id to 0 for the show all and then pick up 0 in your $_GET so that it modifies the SQL not to include a WHERE clause. There are a million ways to skin a cat.
You could choose a category from a dropdown - that way all your data could be in $_POST (or $_GET, I suppose) without any need for js.