Reputation: 313
I'm redesigning a website, and have what I've found to be an interesting problem to solve.
On the original site, there is a list of links; and each link returns its own page that shows almost identical data to the other link pages. The only difference between each of these pages is the sql query that's run upon clicking the link. As a result, there are many redundant pages that, in my mind, could be solved with one smarter page.
I want to have one smarter global page that all the links go to, but want that smart page to be able to know which link was clicked to get there, and will run a different query based on the link it's coming from.
Is there a good/clean way to do this? I am excited by the thought, but am having trouble with implementation.
Thanks in advance for the help!
Upvotes: 0
Views: 261
Reputation: 80
Starting point will be something like this,
page with the list of links -
<ul>
<li><a href="smartpage.php?id=1">Link 1</a><li>
<li><a href="smartpage.php?id=2">Link 2</a><li>
<li><a href="smartpage.php?id=3">Link 3</a><li>
<li><a href="smartpage.php?id=4">Link 4</a><li>
</ul>
smartpage.php -
<?php
$id=$_GET['id'];
switch ($id)
{
case 1:
// Your sql related code
}
?>
Upvotes: 1
Reputation: 585
You can do this by making one PHP file that always checks for a GET query string parameter and display content based on the parameter. The link would be the same but the parameter at the end would be different.
So like this:
Http://www.thelink.com/the_file.php?content=content_1
And then in the PHP file check if $_GET['content']
is set and not empty and have some default content or message if it isn't set as an error checker.
You could do a switch
check to display content if the data structure allows. Else you could do an if else if
type of checks on the value of $_GET['content']
.
Upvotes: 1