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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:21:19+00:00 2026-06-18T12:21:19+00:00

I am just wondering which way to go with a database query. I have

  • 0

I am just wondering which way to go with a database query. I have started using PDO recently with mysql. I am writing a small script that checks for manufacturers and then it checks items against each manufacturer. I am stuck whether it would be quicker to place the items in an array and (only use 1 query) then as i loop for the manufacturer array use an array_count_values to get the item quantities or do a seperate query in the loop to count the items.
I have about 400 manufacturers and 70000 items at present.

my current code using array is :

$itemquery = $conn->query("SELECT manufacturer FROM item_info_short");
$itemquery->execute();
$itemrow = $itemquery->fetchall(PDO::FETCH_ASSOC);
foreach ($itemrow as $itkey => $itvalue) {
   $items[] = $itvalue[manufacturer];
}
$it_qty = array_count_values($items);

and then for my loop :

$manu_query = $conn->query("SELECT manufacturer FROM manufacturers ORDER BY manufacturer");
while($rowsx = $manu_query->fetch(PDO::FETCH_ASSOC)){
    $rowid = $rowsx[manufacturer];
    $count = $it_qty[$rowid];
    if($count == '') $count = 0;
    echo "<option value=\"$rowsx[manufacturer]\">$rowsx[manufacturer]&emsp;$count Items</option>";
}

As you can see i use 2 PDO queries altogether.
The other method would use 401 queries.

I am trying to see which method is best practise and/or quicker.

Thanks in Advance for any advice.

  • 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-06-18T12:21:20+00:00Added an answer on June 18, 2026 at 12:21 pm
    1. Your question is irrelevant to PDO
    2. You’re doing it extremely inefficient way, but it’s irrelevant to the question you’ve asked.
    3. The question you have to ask have to be not “which is faster” but “which is proper way”.

    To get count of manufacturers with cout of their goods, you have to make SQL to count them for you

    SELECT manufacturer, count(*) cnt FROM item_info_short GROP BY manufacturer
    

    will return all manufacturers with their goods count
    if you want to get manufacturer details along – join this query with manufacturers table

    if you need to list all manufacturers with their goods – use LEFT JOIN
    something like this

    SELECT m.manufacturer, count(i.manufacturer) cnt 
        FROM manufacturers m LEFT JOIN item_info_short i
        ON i.manufacturer = m.manufacturer GROUP BY m.manufacturer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just wondering is there a way to List all objects in database which have
I was just wondering which would be cheaper, using a try catch block for
I was just wondering while programming. I have got a rootViewController which creates an
I am using the following which works great. I am just wondering if it
I was wondering about which way i should do the following. I am using
I was just wondering, we have in memory database(IMDB) and we also have a
I'm just wondering which method is the most effective if I'm literally just wanting
I'm new to rails. Just wondering which is the better approach that will return
I am currently working on a web application. I was just wondering which has
Just wondering: I'm trying to set up an adaptive image handler in Coldfusion8, which

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.