How can i fetch only first 5 records in sql using php?

by 4 replies
5
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?
#programming #fetch #php #records #sql
  • 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
  • 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.
  • 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");
  • yet your screen name is programmingking? lol

    SQL Limit - MySQL Limit - SQL Limit Results

Next Topics on Trending Feed