Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display last article on page

Status
Not open for further replies.

rahulpatel

Programmer
Jan 20, 2007
33
AU
I've been following a tutorial and adapting it to my own needs. I want to display the last article I entered but knowing the code is a bit confusing. Here's what I have at the moment.

Code:
// connect to the database
$conn = dbConnect('admin');

// check for article_id in query string
if (isset($_GET['article_id']) && is_numeric($_GET['article_id'])) {
  $article_id = $_GET['article_id'];
  }
else {
  [B]$article_id = 4;[/B]
  }

// prepare SQL query
$sql = "SELECT title, article FROM frontpage WHERE article_id = $article_id";

// process query
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_assoc($result);
?>

I currently have to amend the line in bold to the last article to get it to show. I realise it's going to be pretty simple but I don't know how to do it. Any ideas? Thanks.
 
The code you provided is used to display an article that is requested via sending its ID through the URL. Like:

myscript.php?articleid=4

If you simply want to get the latest article, I suggest you do that with a SQL query, extracting just the one you want (latest by date, highest ID, and so on).

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Code:
$sql = "SELECT title, article FROM frontpage order by article_id DESC LIMIT 1";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top