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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:30:07+00:00 2026-05-18T00:30:07+00:00

my $sth = $dbh->prepare(SELECT id FROM user WHERE group == ‘1’ ORDER BY id

  • 0
my $sth = $dbh->prepare("SELECT id 
                           FROM user 
                          WHERE group == '1' 
                       ORDER BY id DESC 
                          LIMIT 1");

I was trying to get the id of the last row in a table without reading the whole table.

I am already accessing via:

my $sth = $dbh->prepare("SELECT name,
                                group 
                           FROM user 
                          WHERE group == '1' 
                          LIMIT $from, $thismany");
$sth->execute();
while(my ($name,$group) = $sth->fetchrow_array()) {

…and setting up a little pagination query as you can see.

But, I am trying to figure out how to detect when I am on the last (<= 500) rows so I can turn off my “next 500” link. Everything else is working fine. I figured out how to turn off the “previous 500” link when on first 500 page all by myself!

I thought I would set up a “switch” in the while loop so if ($id = $last_id) I can set the “switches” var.

Like:

if ($id = $last_id) {
$lastpage = 1; #the switch
}

So I can turn off next 500 link if ($lastpage == 1).
I am really new to this and keep getting stuck on these types of things.

Thanks for any assistance.

  • 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-18T00:30:08+00:00Added an answer on May 18, 2026 at 12:30 am

    Try to grab an extra row and see how many rows you really got. Something like this:

    my @results = ( );
    my $total   = 0;
    my $sth     = $dbh->prepare(qq{
            SELECT name, group 
            FROM user 
            WHERE group = ?  
            LIMIT ?, ?
    });
    $sth->execute(1, $from, $thismany + 1);
    while(my ($name, $group) = $sth->fetchrow_array()) {
            push(@results, [$name, $group]); # Or something more interesting.
            ++$total;
    }
    $sth->finish();  
    
    my $has_next = 0;
    if($total == $thismany + 1) {
        pop(@results);
        $has_next = 1;
    }
    

    And BTW, please use placeholders in all of your SQL, interpolation is fraught with danger.

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

Sidebar

Related Questions

I have a sql like this: SELECT * FROM tableA WHERE column_a = sth
I have a select statement, sth like.. select col1, col2, col3 from tbl1 where
Is it possible to get as a result from hibernate directly this... List<Map<Sth, List<SthLog>
I'm trying to get a web.py application running on GAE. I hoped that sth
I'm trying to add some navigation controller in my app, it's sth likes: in
I'm copying ListViewItems from one ListView to another, sth. like: foreach (ListViewItem item in
User model looks sth like this: before_save :ensure_authentication_token devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,
I'm trying to draw equations to the screen. Not the graphs or sth just
I have this problem with probing integer from TempData as it sees DempData[sth] as
i want to do sth like this: <HierarchicalDataTemplate x:Key=BuildingTemplate ItemsSource={Binding Path=RoomAccesses.Select(p => p.Room)} ItemTemplate={StaticResource

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.