Hi, I have a website with some menu options/links.
All pages are essentially the same except for a php loop that selects different content from a json file. So I was wondering how to reload a page and just run different php code depending on the selected menu option.
Thanks for any help
How to reload page, rerun php code – PHP – SitePoint Forums

It depends on what kind of links it is. If they are normal links, you can paste a code at the end of the URL and, when you display the page, provide the appropriate content for this code. If it’s a
you can use Javascript to trap the
onChange()
event, call a small script to get the different contents, and insert it directly into your document.
JavaScript is used to modify pages in the browser without making another round trip to the server. You can drastically reduce and even completely eliminate round trips to the server by creating a SPA rather than a series of chained web pages on a traditional server. The old way is to piece together the partial HTML mail fetched from the server and add it to the page using JavaScript. However, there are an overwhelming amount of downsides to this large-scale approach. Thus the rise of modern MVVM (model-view-view-model) innovations; React, Vue and Angular. React and Vue are designed to be easily inserted into an existing website like yours probably. Web experiences that eliminate trips to the server are also more environmentally friendly. Think of it as saving unnecessary energy to consume using modern tools and methodologies.
Thank you very much for this, I’m new to PHP and Javascript so I don’t know how to implement your solutions.
The links I have are:
Oil on
Canvas
Acrylic, Pencil,
Water Color
And the php code that I need to change
if ($entry['medium'] == "Oil on canvas") {
at
if ($entry['medium'] == "Acrylic") {
I would like to use only index.php and not have to redirect to acrylic.php. Any snippets on how I can do this are much appreciated.
Thanks
The easiest, if you can change things up a bit, would be to change your links to be:
Oil on
Canvas
Acrylic, Pencil,
Water Color
And then your menu code:
if (strtolower ($_GET['medium']) == "oil") {
1 like
Thanks Tracknut,
It worked perfectly – after adding
(! isset($_GET['medium'])
to the mixture.
Very appreciated.
1 like