ludjer Posted August 31, 2006 Share Posted August 31, 2006 here is my code[code]<?phprequire_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 databasethx ludger Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 31, 2006 Share Posted August 31, 2006 $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 doneEDIT: replace 'date' for the fieldname in your database where you store the date/datetime stampRegardsLiam Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 31, 2006 Share Posted August 31, 2006 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 :( ;) Quote Link to comment Share on other sites More sharing options...
ludjer Posted August 31, 2006 Author Share Posted August 31, 2006 thx alot will try now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.