Page 1 of 1

Refresh page with new content on clicking a link

Posted: Mon Aug 07, 2006 12:45 pm
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.

Posted: Mon Aug 07, 2006 2:45 pm
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

Posted: Mon Aug 07, 2006 6:14 pm
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" ?

Posted: Tue Aug 08, 2006 2:42 am
by andym01480
Absolutely!