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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:41:04+00:00 2026-05-20T03:41:04+00:00

Sorry for my inaccurate syntax. New to this. I need to select part numbers

  • 0

Sorry for my inaccurate syntax. New to this.

I need to select part numbers in three different groups.

A different qty for each group.

Each group individually sorted ABS desc.

my $fromrow = CGI::param('from');## vague but put here to show a sort of pagination  ## 
my $nextrow = CGI::param('next');
my $grabpartnumbers = $hookup->prepare(qq{
   SELECT `New`,`Used`,`NOS`,`PartNum`,`Description`,`Price`
   FROM `Partstable`
   WHERE `instock` = ? AND `QTY` > ? AND `New` = ?
   ORDER BY ABS(PartNum) LIMIT ?,?});
$grabpartnumbers->execute('1','10','1',$fromrow,$nextrow);
while(@row = $grabpartnumbers->fetchrow_array()) {
#do stuff

Works fine, for one “column” eg “New”.
However, I want to display like:

New Stock
4 results

NOS
6 results

Used Stock
10 results

Additional problems will arise for me when one of the three “columns” have no more data to display. At that point, I just want to display the remaining result or nothing (not even the title header) if results = 0 for that cat.

Is this possible or do I need to prepare three different queries and possibly push each into their own arrays to decipher what to display in some loops?

This is VERY advanced for me so, please be verbose with examples. (dumb it down to my level of comprehension (-; )

Thanks..

EDIT:

My Partstable rows look like

   ID|PartNum|New|Used|NOS|Qty|instock|Description|Price
    1|132452 |1  |0   |0  | 24|y      |12ax7 yada |3.00

I want to display three “areas” on the same page by order of “importance”. “New” take priority.

New Stock 4 results

NOS 6 results

Used Stock 10 results

  • 1 1 Answer
  • 1 View
  • 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-20T03:41:05+00:00Added an answer on May 20, 2026 at 3:41 am

    What you need to achieve is a little bit difficult to precisely comprehend, but it looks like you could potentially be just fine with a full-SQL solution (clever use of GROUP BY, etc.).

    Regarding the current solution with Perl, and assuming I understand your example correctly, something like this would work as a starting point for you to play around and adapt to your actual dataset.

    Warning: Code tested against syntax only!

    my $fromrow = CGI::param('from');## vague but put here to show a sort of pagination  ## 
    my $nextrow = CGI::param('next');
    
    # Columns of interest, sorted by descending order of importance
    my @interesting_columns = qw(
        New
        Used
        NOS
        PartNum
        Description
        Price
    );
    
    my $interesting_columns_expr = join(', ', map { $_ = "`$_`" } @interesting_columns);
    my $grabpartnumbers = $hookup->prepare(qq{
        SELECT $interesting_columns_expr
        FROM `Partstable`
        WHERE `instock` = ? AND `QTY` > ? 
        ORDER BY ABS(PartNum) LIMIT ?,?
    });
    $grabpartnumbers->execute('1','10',$fromrow,$nextrow);
    
    # Compute results
    my %result_counter;
    while ( my $row = $grabpartnumbers->fetchrow_hashref() ) {
        foreach my $column_name ( keys %$row ) {
            $result_counter{$column_name} += $row->{$column_name};
        }
    }
    
    # Display results
    for my $column_name ( @interesting_columns ) {
        if (exists $result_counter{$column_name}) {
            print join( ':', $column_name, $result_counter{$column_name} );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry if this is stupid question, but I'm new to MATLAB. I have a
Sorry, I'm new to SVN and I looked around a little for this. How
Sorry if this sounds like a really stupid question, but I need to make
Sorry this is basic, but I'm new to Python and Django. I have a
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
Sorry I am very new to open graph and have been having difficulty to
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,

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.