2 replies [Last post]
BigToque
BigToque's picture
Offline
newbie
Last seen: 32 weeks 4 days ago
Timezone: GMT-6
Joined: 2005-01-08
Posts: 6
Points: 0

How can I set a website to load a certain database record on a page load when the page is opened with a link embedded in the site?

I have a page that lists a bunch of game recaps from my hockey team. I want to be able to click a link beside each game that loads up a new page that shows the recap for the game.

I see it all the time with something like:

http://www.domain.com/recap.php?=someID

how do you get the "someID" part into a variable when recap.php loads?

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 2 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

Loading certain database records with html link?

Hi BigToque,
It's usually http://www.domain.com/recap.php?myvar=someID
Then php reads the variable like

<?php 
if(isset($_GET['myvar'] ) && $_GET['myvar'] !=""){ 
   $myvar=$_GET['myvar']; 
} 
?>
then of course you need to work out what to do with it, which really depends on how the content is stored, in a database or files.

Hope that helps

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 2 years 2 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

Loading certain database records with html link?

Well, you can do this with or without a DB. You could just create a page that has the recap info and create a link to that page...
<a href="www.blah.com/game1.html">Game One</a>
Or you could put game1.html in the DB or you could put the entire recap into the DB...
It all depends on how you want to do it...
I don't use PHP, I use ASP but the idea is the same... and I dynamically create my content so I have to use two pages to accomplish this...
The info stored in the DB gets an ID either autoassigned or manually and then you need columns for your headline and content
I have 3 columns in my DB table
ID=2
Headline=Game 2
Recap=has the game recap or it could just contain the link to the page that has the recap
Then I run a query of the database to generate my links... lets say the page is games.asp... the query then returns a list of all my games and I get something like this
Game 2 which is the text that is displayed and the a href tag looks like
http://www.domain.com/displaygames.asp?=2
The displaygames.asp page runs a query on the DB that returns the info for ID=2 based on the querystring which is the above url

This might be over complicated but maybe gives you and idea?