pulling the last 5 records from the db and counting number

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gasoga
Forum Commoner
Posts: 36
Joined: Thu Apr 17, 2003 4:15 am
Location: Ireland

pulling the last 5 records from the db and counting number

Post by gasoga »

Hi ,

i am having trouble with pulling the last five records that a user submits to the database , i was wondering if anybody could tell me how do i pull the last 5 records that a user submits to the database , and then check to see if there is a value in certain coulems of each record??!!!
Any advice woudl be much appreciated!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Okay,

not gonna tell you how to do it, but will give you some guidlines.

Construct a query to count total number of rows, using COUNT().

Then, create a query using LIMIT. subtract 5 from total number of rows in DB and LIMIT the result from that number to the maximum number.

Mark
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Or (more guidelines) select using 'order by date desc' and LIMIT 5...
Depends on how the table is setup.
Post Reply