I have a grocery store web page index.html with a navigation to different product categories (Fruits, Meats, Snacks etc...), then I have a page named aisle.php which will display all of the products from the category, and it gets all of the products from a json file. I'm wondering how do I redirect to the aisle.php page and load the products I want, since I need to know which link was clicked. I'm new to php and json and it's what we are required to use for our class, thanks in advance!
Image of the aisle page with sample products hardcoded
CodePudding user response:
you can form your link to aisle.php with a parameter in query string like so :
<a href='aisle.php?content=Meats'></a>
and in aisle.php your can check the parameters via $_GET variable and show the products you need
CodePudding user response:
There are several ways of doing this :
- using GET variables (probably the easiest as a beginner, but also the dirties)
- using POST variables (through an HTML form)
- setting up an URL redirection (cleanest but probably not easy to beginners)
Once your variable is sent, you can save it into a SESSION or a COOKIE.
I suggest you read about PHP superglobals