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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:23+00:00 2026-05-29T05:18:23+00:00

I have this class in PHP, and I have been trying to get all

  • 0

I have this class in PHP, and I have been trying to get all the variables using a function, but the problem is in my database there are more than 1000 rows, so I will use the SELECT statement each time the class called. For instance

        class person
        {
            var $id; // this id will be passed to function get_all()

            var $name;
            var $age;
            var $salary;

            function get_all($id)
            {
                $Query = 'SELECT FROM `person` WHERE `id` = '.$id.'';
                /*
                code to excute the query
                */

                $this->name = somthing;
                $this->age = somthing;
                $this->salary = somthing;
            }
        }

So now I don’t know if this method it’s the same when I use this method in my PHP code ?

    $Query = 'SELECT * FROM `person`';

    /* excute the Query .. */

    foreach($person_array as $person)
    {
        // I don't know how to make it especially beacause it's dynamic
    }

Is there any possible way to use the same class with use 1 Query ? or if the first method will not make any problem please tell me.

  • 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-29T05:18:24+00:00Added an answer on May 29, 2026 at 5:18 am

    Just modify your first function:

    function get_all($id) {
        $Query = 'SELECT * FROM `person`;';
        /*
        code to excute the query
        */
        foreach (/*your foreach statements here*/) {
            $person = new Person; // Create a new person object for each record
            $person->name = somthing;
            $person->age = somthing;
            $person->salary = somthing;
            $persons[] = $person; // Add this person to an array
        }
        return $persons; // Return an array of person objects, containing everyone
    }
    

    Using this method is efficient, and will return an array of all the persons you want.

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

Sidebar

Related Questions

I currently have my PHP class variables set up like this: class someThing {
I have this in my class When the second function is called php errors
I've been trying to get an existing project working on local copy but have
I am trying to connect to Webtrend's API using PHP but haven't been able
I am trying to get a guest book to work using PHP. I have
Hey most of my issue has been solved but i have little problem This
Hi been trying to get this to work for ages, i have a deals
I have a url that look like this reg.php?lang=no_NO&passkey=test and im trying to get
I have been using Micah Carrick's PAYPAL IPN class till now for web_accept but
Hallo I have this script: <? require(lib2/config.inc.php); require(lib2/tpl.class.php); require(lib2/db.class.php); require(lib2/um.class.php); $tpl = new template(templates,

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.