Passing value from HTML link to use in php if statement on next page
I currently have a menu with 4 links, and each link goes to its own php file/page like so:
<!--Page One-->
<a href="temp_one.php"><h5 >Template One</h5></a>
<a href="temp_two.php"><h5 >Template Two</h5></a>
<a href="temp_three.php"><h5 >Template Three</h5></a>
<a href="temp_four.php"><h5 >Template Four</h5></a>
I'm refactoring this so that I only use one single file that conditionally sets the HTML for the page depending on which link was selected, probably by using GET
I want to change it to get values for each link that direct to a new single page, template.php, and use the value for the page so that the new url would effectively look like this:
template.php?1
template.php?2
template.php?3
template.php?4
So essentially the same as doing this:
<a href="template.php?1"><h5 >Template One</h5></a>
<a href="template.php?2"><h5 >Template Two</h5></a>
<a href="template.php?3"><h5 >Template Three</h5></a>
<a href="template.php?4"><h5 >Template Four</h5></a>
The reason is that I want to be able to use the values in an if statement on template.php so that I know which HTML to use like so:
<!--Page Two, template.php-->
if(value = 1){
//HTML for template one
}
elseif(value=2){
//HTML for template two
}
elseif(value=3){
//HTML for template three
}
else{
//HTML for template four
}
How can I modify the html of the links to supply the proper value to use in the next page with an if statement?
Answer
Solution:
You can do like this:
Pass a variable indicating the template value through URL.
And in php file
template.php
,$_GET
that variable.And in
template.php
,$value = isset($_GET['value']) ? $_GET['value'] : 1; // Where 1 is default value.