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

Best way to show the SQL trace of a LINQ query to Entity Framework
This way I get the reference to the open window: var refWin = window.open(mypage1,
By way of explanation, take this value type in C#: struct ObjRef { public
If I try to execute the following code, I get the errors Msg 207,
Way back in 2000, I did some ETL development with SQL Server DTS packages.
Which way do you prefer to create your forms in MVC? <% Html.Form() {
Typical way of creating a CSV string (pseudocode): Create a CSV container object (like
The way you would normally include a script is with source eg: main.sh: #!/bin/bash
The way I do 80-column indication in Vim seems incorrect: set columns=80 . At
The way the iPhone uses the touchscreen to enable zooming in and out and

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.