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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:25:29+00:00 2026-06-18T06:25:29+00:00

I have a simple articles table with IDs. I want to get the highest

  • 0

I have a simple articles table with IDs. I want to get the highest and lowest ids from the latest 10 results. For example, if there are 11 ids, the result should be 2 and 11 and if there are 4 ids, should be 4 and 1 and so on. I use PHP PDO statements.

$aid = $DBH->prepare("SELECT id FROM articles ORDER BY id DESC LIMIT 10"); 
$aid->execute(); 
$row = $aid->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);
$lowest_article_id = $row[0];
$row = $aid->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST);
$highest_article_id = $row[0];

The above will always return 11 if there are 11 records and 10 if there are 10 records. So, the query ignores the PDO::FETCH_ORI_LAST part of the query.

Thanks

  • 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-06-18T06:25:30+00:00Added an answer on June 18, 2026 at 6:25 am

    I did some checking and from the docs it sounds like this should work. You need to enable cursor scrolling when you prepare the sql.

    $aid = $DBH->prepare("SELECT id FROM articles ORDER BY id DESC LIMIT 10", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); 
    $aid->execute(); 
    $row = $aid->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);
    $lowest_article_id = $row[0];
    $row = $aid->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST);
    $highest_article_id = $row[0];
    

    That being said it does not for me :/

    I did more reading/testing and I found these two bug reports:
    https://bugs.php.net/bug.php?id=34625 (this one is from 2005 though and I am almost positive there is cursor functionality in MySQL these days).
    https://bugs.php.net/bug.php?id=57623

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

Sidebar

Related Questions

I have a simple articles table and want to select the lowest ID from
I have articles table, article_comments. I want to get the value: last_modified_all of article.
I have a simple cakephp app with table articles that has a cat_id column
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
I have a simple DB-table with few fields for articles database among that is
I have a simple article and comments system with the following tables: Articles table:
I want to know is there any way to have editable table in ASP.net
I have always seen in python articles/books that python is simple and it has
I have a really simple Rails app. Basically an article with comments. I want
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (

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.