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 7618831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:30:21+00:00 2026-05-31T03:30:21+00:00

My code get the last 10 values from a table. This table has te

  • 0

My code get the last 10 values from a table. This table has te structure id,text and by the moment it has 20 rows. I use this piece of code

<?php
$query = mysql_query("SELECT * FROM `table` ORDER BY `id` DESC LIMIT 10");
// Fetching data stuff here
?>

and it returns the data for IDs 11-20. (The last 10 of the 20)

I want to get the previous 10 values from this 1-10 via AJAX. I thought maybe this will work

$previous_id= $_GET["last"];  // This time it will be 11
mysql_query("SELECT * FROM `table` ORDER BY `id` DESC LIMIT $previous_id, -10");

But I’m doesn’t, any suggestion?

Thanks

PS: This is not a gimme teh codez question, I just want to know how to make that query work.

  • 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-31T03:30:23+00:00Added an answer on May 31, 2026 at 3:30 am

    If I understand you correctly you want to get the 10 rows before the row with id = $previous_id, ordered by descending ID.

    If that’s the case your best bet would be to use a WHERE condition. As you are ordering by id DESC you want the first 10 rows with id > $previous_id:

    SELECT * FROM `table` WHERE `id` > $previous_id ORDER BY `id` DESC LIMIT 10
    

    These will be the 10 rows before $previous_id in your original query.

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

Sidebar

Related Questions

When getting all values from db table, I get this error on the last
I'm trying to change some php code so that i get my values from
How can I get last year's start and end date using PHP code? Is
I want to get the values from a particular column of a table. Whats
I'm learning to put values into my db from php. this is my simple
Possible Duplicate: PHP: how to get last inserted ID of a table? I am
With the below code, I get the columns size being different (esp the last
I'm currently using the following PHP code: // Get all subordinates $subords = array();
My code: $.get('ajax/time_menus.php', { shift: $('#shifts').val() }, function(data) { //load the array into a
I am pulling data from an XML feed via C# code. When I get

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.