Jump to content


Photo

X--SOLVED--Xnoob here needs help


  • Please log in to reply
3 replies to this topic

#1 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 31 August 2006 - 05:58 PM

here is my 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 }?>

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

thx
ludger
:D

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 31 August 2006 - 06:02 PM

$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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 August 2006 - 06:02 PM

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

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

Umm too slow shocker beat me :( ;)

#4 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 31 August 2006 - 06:02 PM

thx alot will try now

:D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users