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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:36:14+00:00 2026-05-31T23:36:14+00:00

I’ve a table with more than 5000 rows. Each row has a category, and

  • 0

I’ve a table with more than 5000 rows. Each row has a category, and I want to use these rows in my program. The problem is do I analyze these rows each time inside classes ? Or get only the class need each time, and make each class decide which data to use. I know my explanation is a mess, but look at these to examples.

    PEOPLE
    --
    ID      NAME            CAT     AGE
    ------------------------------------
    1       Brad             5      23
    2       Goy              3      19
    2       Romeo            5      34
    2       Deborah          5      40
    ..      ..          ..      
    5000    Bob              1      56

now I want only to analayze the rows with cat = 5 and each row will be an object.

    First Solution 

    SELECT * FROM people Where CAT = 5
    and then in php make each class analyze the all data ? 

    foreach($people as $p)
    {
        if($p['age'] == 20)
        do......
    }

    Second solution
    in each class put a function to get the data

    function get_data
    {
        $query = 'SELECT * FROM people WHERE cat = 5 AND age = '.$this->age.'';
        then do....
    }

I HAVE A LOT OF ROWS 5000 it’s an example, please help me and give me the more efficent solution
the first one will hit the databse once but the same array will loop in each class (not good)
the second will hit the database many times but will bring the indeed needed data.

  • 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-31T23:36:16+00:00Added an answer on May 31, 2026 at 11:36 pm

    With no details given, the answer is certainly to filter data with the SQL query for many reasons. There are some situations though when db-level processing is not possible (e.g. when more complicated business logic is involved) but generally you should always try to filter data before it gets into your high-level code.

    That’s precisely the job databases were invented for.

    In your example, collect all your ages in an array first and then run the following query:

    $sql = 'SELECT * FROM people WHERE cat = 5 AND age IN (' . implode(',', $ages) . ')';
    

    If you’re using MySQL, the allowed size of IN sets is huge (32 Mb by default) which should be enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.