Refresh page with new content on clicking a link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KBC
Forum Newbie
Posts: 6
Joined: Mon Aug 07, 2006 12:34 pm

Refresh page with new content on clicking a link

Post by KBC »

Hi,

I'm new to PHP (and just really starting out) and forgive me if I posted this in the wrong forum and the question that follows. ;)

I have a website which is database (MySQL) driven. I have it set up so that it would pull the newest article from the database table and display it based on the timestamp on the front page.

Code: Select all

article_id
article_title
article_text
article_timestamp
The front page will also select ALL the articles from the table above and display it on the front page by "article_title" only, so almost like an "Archived Articles" section. But how would I make these linkable such that when a user clicks a link, it will automatically refresh the front page and displace the newest article with the requested article?

Is this where I have to pass arguments in the URL based on the "article_id" ?

Hope you can help.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Yes

Next to an article title have something like

Code: Select all

echo "<a href=\"frontpagename.php?art=$article_id\">Click to see article</a>";
where $article_id is the article_id for that article_title!

Then at the top of the page have something like

Code: Select all

if (ctype_digit($_GET['art'])){//checks a link has been clicked and that a decimal digit was returned
$article_id=$_GET['art'];

//process to display that article
}
Hope that helps
KBC
Forum Newbie
Posts: 6
Joined: Mon Aug 07, 2006 12:34 pm

Post by KBC »

andym01480 wrote:Yes

Next to an article title have something like

Code: Select all

echo "<a href="frontpagename.php?art=$article_id">Click to see article</a>";
where $article_id is the article_id for that article_title!

Then at the top of the page have something like

Code: Select all

if (ctype_digit($_GET['art'])){//checks a link has been clicked and that a decimal digit was returned
$article_id=$_GET['art'];

//process to display that article
}
Hope that helps
Hi, thanks for your response... the part which says "//process to display that article" - I gather this is where I do a SELECT query and echo the "article_text" for that particular "article_id" ?
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Absolutely!
Post Reply