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

  • Home
  • SEARCH
  • 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'm trying to get a web.py application running on GAE. I hoped that sth
I wanna extract https://www.sth.com/yment/Paymentform.aspx from below string <form id='paymentUTLfrm' action='https://www.sth.com/yment/Paymentform.aspx' method='post'> How can I
I have just installed darcs 2.1.2.2. When I type darcs help, sth less-like shows
The following code gives a segmentation fault on the last line require 'rubygems' gem
$(sth).not(':animated').animate(); hey is this the best way to animate element after being sure that
im looking for sth like: udpsend [udp-data] [target-ip] [target-port] eg. c:\>udpsend Hello, World 192.168.1.111
I want to code sth. that basically works like TiVo. Switch it on, you
I want to do sth. like this: foo=(a b c) foo-=b echo $foo #
I want to report sth every new month via email. How can i do
I'm implementing global search box extension (sth like SearchableDictionary sample in android sdk). Everything

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.