Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 14th Jul 2013, 09:30 PM   #1
Warrior Member
 
programmingking's Avatar
 
Join Date: 2013
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default
How can i fetch only first 5 records in sql using php?
Share on: 
fb share twitter share gplus share more share

Hello people

i am using mysql database with php. I have 1000+ records in my table. I want to fetch only first five records in php page how can i do that?
programmingking is offline  
Unread 14th Jul 2013, 09:32 PM   #2
Active Warrior
 
skillboyz's Avatar
 
Join Date: 2013
Location: AU
Posts: 57
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: How can i fetch only first 5 records in sql using php?
Share on: 
fb share twitter share gplus share more share

You can use simple sql statement to fetch top 5 records you can use limit clause for it. here is an example of it

select * from tablename limit 0,5

hope it helps
skillboyz is offline  
Unread 15th Jul 2013, 11:57 AM   #3
I Code Stuff
War Room Member
 
dad2four's Avatar
 
Join Date: 2011
Location: Kirkwood, MO USA
Posts: 302
Thanks: 210
Thanked 80 Times in 52 Posts
Default
Re: How can i fetch only first 5 records in sql using php?
Share on: 
fb share twitter share gplus share more share

You'll wand do do an order by to be sure you get the 5 you want.

Also keep in mind you may need ASC or DESC depending on what you are ordering by. Especially if you are ordering by dates.

dad2four is offline  
Unread 22nd Jul 2013, 07:18 AM   #4
SKT Wordpress Themes
War Room Member
 
sktthemes's Avatar
 
Join Date: 2013
Location: Nagpur
Posts: 65
Thanks: 5
Thanked 28 Times in 11 Posts
Default
Re: How can i fetch only first 5 records in sql using php?
Share on: 
fb share twitter share gplus share more share

Hello
You can use simple mysql query for displaying first five records
mysql_query("select * from table_name order by ID ASC LIMIT 0, 5");

sktthemes is offline  
Unread 22nd Jul 2013, 01:52 PM   #5
Web Developer
War Room Member
 
Andrew H's Avatar
 
Join Date: 2012
Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
Default
Re: How can i fetch only first 5 records in sql using php?
Share on: 
fb share twitter share gplus share more share

yet your screen name is programmingking? lol

SQL Limit - MySQL Limit - SQL Limit Results

"You shouldn't come here and set yourself up as the resident wizard of oz."
Andrew H is offline  
Closed Thread


Bookmarks

Tags
fetch, php, records, sql


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:13 PM.