Current location: Hot Scripts Forums » Programming Languages » PHP » Select say last 5 database entrys only


Select say last 5 database entrys only

Reply
  #1 (permalink)  
Old 08-18-04, 11:34 AM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Select say last 5 database entrys only

Hello all

I have finished a site and am now starting to worry what can go wrong : (

First thing I have thought of is that I am displaying all the items in the database and this page could get very large.

What I would like to do is display only the last 5 items input and anything else would have to be searched for.

Below is my current query; can someone help me out please.

Anthony

PHP Code:

// Quick note - apporve only displays items that have been vetted by the site admin.

$query "SELECT text, title, id, DATE_FORMAT(date_l, '%d %M %Y') AS date FROM table WHERE approve ='Y'"
Page - http://www.b-secure.biz/lost/list.php
Reply With Quote
  #2 (permalink)  
Old 08-18-04, 12:38 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
PHP Code:

$query "SELECT text, title, id, DATE_FORMAT(date_l, '%d %M %Y') AS date FROM table WHERE approve ='Y' ORDER BY id DESC LIMIT 0,4"
Reply With Quote
  #3 (permalink)  
Old 08-18-04, 02:12 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the help Keith; I will give it a go but cant tell if it works yet as I only have one entry in the database so far !

Anthony
Reply With Quote
  #4 (permalink)  
Old 08-18-04, 03:43 PM
steveo steveo is offline
Wannabe Coder
 
Join Date: Jun 2004
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Keith, what does the 0,4 stand for?

When I do mine, I do the same as you but put the full number there, eg 10.

Is there any difference?
Reply With Quote
  #5 (permalink)  
Old 08-18-04, 06:44 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Oops, that should be 0,5... stupid typo.

No difference really, it means you start at zero and count up to 5. It's used better if you're spanning hundreds or thousands of rows over many pages.

Last edited by Keith; 08-18-04 at 06:57 PM.
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
Why won't select list item insert into database? gavacho PHP 2 12-05-08 06:38 PM
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
i have 3 select box this is urgent traceMe JavaScript 0 12-02-03 01:24 AM
PHP Can't select database EST PHP 4 08-19-03 10:14 AM


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