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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:57:23+00:00 2026-05-23T11:57:23+00:00

Way oversimplified example: # Get Some data $query = $db->prepare(qq{ select * from my_table

  • 0

Way oversimplified example:

# Get Some data
$query = $db->prepare(qq{
    select * from my_table where id = "Some Value"
});
$query->execute;

# Iterate through the results
if ( *THE QUERY HAS RETURNED A RESULT* ) {
    print "Here is list of IDs ";
    while ($query_data = $query->fetchrow_hashref) {
        print "$query_data->{id}";
    }
};

Looking for the code for “THE QUERY HAS RETURNED A RESULT” up there. I’d like to avoid using count(*) in my SQL if possible, since that will require a “group by”.

  • 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-23T11:57:24+00:00Added an answer on May 23, 2026 at 11:57 am
    my $sth = $dbh->prepare($stmt);
    $sth->execute();
    
    my $header = 0;
    while (my $row = $sth->fetchrow_hashref) {
        print "Here is list of IDs:\n" if !$header++;
        print "$row->{id}\n";
    }
    

    Alternative:

    my $sth = $dbh->prepare($stmt);
    $sth->execute();
    
    my $row = $sth->fetchrow_hashref;
    print "Here is list of IDs:\n" if $row;
    while ($row) {
        print "$row->{id}\n";
        $row = $sth->fetchrow_hashref;
    }
    

    Simpler code at the expense of memory:

    my $ids = $dbh->selectcol_arrayref($stmt);
    
    if (@$ids) {
        print "Here is list of IDs:\n";
        print "$_\n" for @$ids;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which way is preferred in expressions like this: int? Id { get { int
The way automatic variables/local variables go on to stack,dynamically allocated objects/data type go on
Any way to install a bookmarlet in Mobile Safari from a native app? Has
This way surely works,but it calls UNIX_TIMESTAMP 2 times: mysql> select UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP('2009-09-23
If I try to execute the following code, I get the errors Msg 207,
The way DUnit normally works is you write some published methods, and DUnit runs
The way to iterate over a range in bash is for i in {0..10};
Way back in 2000, I did some ETL development with SQL Server DTS packages.
Best way to elaborate on the question is to give an example of what
Any way to make this less verbose? var model = ( from MvrTable in

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.