Current location: Hot Scripts Forums » Programming Languages » PHP » Select last entry from DB


Select last entry from DB

Reply
  #1 (permalink)  
Old 11-21-03, 02:26 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Select last entry from DB

I have a mysql db but i want mysql to select with a limit for 4 rows but it must be the last 4 rows in the table as this db will be updated daily.

PHP Code:

$sql "SELECT * FROM news LIMIT 0, 4"
how do I do this ?
Reply With Quote
  #2 (permalink)  
Old 11-21-03, 04:04 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
PHP Code:

$sql "SELECT * FROM news LIMIT 0, 4"
You can use this...

$sql = "SELECT * FROM news ORDER BY id DESC LIMIT 4";

This gives you the 4 newest entries, in descending order. Use ASC to reverse them.
Also can by ordered by timestamp, if you have one inserted in a field.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Skin awais PHP 5 01-02-04 02:37 PM
Help me select a e-commerce system omnidust Script Requests 3 10-08-03 12:38 AM
Insert...select andreasberglind PHP 5 08-21-03 05:07 PM
PHP Can't select database EST PHP 4 08-19-03 10:14 AM
What if there is no entry? Cagez PHP 3 07-29-03 02:06 AM


All times are GMT -5. The time now is 05:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.