Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:02:41+00:00 2026-05-25T06:02:41+00:00

I want to return only the last 15 rows in my table, then the

  • 0

I want to return only the last 15 rows in my table, then the 15 before that.

Unfortunately while($rows = mysql_fetch_assoc($result)) where the query is SELECT * FROM table returns the data in all rows.

I thought about doing something like:

In my insert script

SELECT * FROM table then $selection_id = mysql_num_rows($result)-14 before inserting any data, then adding column named selection_id which would contain $selection_id, thus each set of 15 rows would have the same selection_id.

In my select script

SELECT * FROM table then $num_rows = mysql_num_rows($result)/15 then SELECT * FROM table WHERE selection_id='$num_rows' and SELECT * FROM table WHERE selection_id='$num_rows-1'.

I could then perform while(..) on both results as usual.

However, I’m not sure this is the most efficient way (chances are it’s not), so if not, I’d really appreciate some suggestions to cut down the amount of code I’ll have to use :)!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:02:42+00:00Added an answer on May 25, 2026 at 6:02 am

    Use a LIMIT clause in your query, order by your auto-incrementing primary key in descending order. E.g.

    SELECT * FROM `table` ORDER BY `selection_id` DESC LIMIT 0,15
    

    …will get the last 15 rows, and:

    SELECT * FROM `table` ORDER BY `selection_id` DESC LIMIT 15,15
    

    …will get the 15 rows before that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run a basic query, but return only the first ten rows
Given my following table structure: I'm trying to build a query that will return
I want to implement all my own rotation animations but if I only return
I want to merge this queries into only one, to return 2 values (scount_atp
I want regExp to test for two 'Hello'-s and return true but it only
How can I return the key?, mean if I want to allow only integer
I want to return a simple json result, something like: { 12323: true }
In my table view I had more than 200 rows and Im managing then
A question that has pondered me for the last while. I am primarily a
i have a simple html table where i want to delete and add rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.