Jump to content

Archived

This topic is now archived and is closed to further replies.

ludjer

X--SOLVED--Xnoob here needs help

Recommended Posts

here is my code
[code]
<?php
require_once('../config/database.php');
require_once('../config/newschecksesion.php');

$result = mysql_query("SELECT * FROM news");

while ( $row = mysql_fetch_array($result) )
{?>

<div style="width:450px;">

<h3><u>title:<br />
<?php echo @$row['title']; ?></u></h3>
<p>content:<br />
<?php echo @$row['content']; ?></p>
<p><b>Posted On:</b><i><?php echo @$row['date']; ?> by <?php echo @$row['user']; ?></i></p>
<hr />

</div>


<?php }?> [/code]

now how do i only read the latest rows that where put into the database

thx
ludger

Share this post


Link to post
Share on other sites
$result = mysql_query("SELECT * FROM news");

needs to be

$result = mysql_query("SELECT TOP 5 * FROM news ORDER by date DESC");
or
$result = mysql_query("SELECT * FROM news ORDER by date  DESC LIMIT 5");


Just an example of how it can be done

EDIT: replace 'date' for the fieldname in your database where you store the date/datetime stamp

Regards
Liam

Share this post


Link to post
Share on other sites
What do you mean by 'latest rows', do you mean the last row or the last couple of rows. If its the last row and you have an auto incrementing id field you can use mysql_insert_id to grab the latest inserted record. Or if you want the last couple of rows use LIMIT and ORDER BY

[code]SELECT * FROM news ORDER by id_col DESC LIMIT 3[/code]
That'll grab the last 3 rows in the news table.

Umm too slow shocker beat me :( ;)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.