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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:42:00+00:00 2026-06-14T12:42:00+00:00

There is probably a very simple explanation for this, but I’ve had this code

  • 0

There is probably a very simple explanation for this, but I’ve had this code working for months, and now all of a sudden today it doesn’t work.

I retrieve all the rows from a table. I have and object which is an entity model of the table I’m selecting from. As I read the rows from the associative result array, I’m storing each property using “$this->propertyName,” and then I’m pushing each object to an array. Before I ended up with an array of objects, now I end up with an array of the same object repeated. Here’s a code snippet:

     $mdSelectALL_sql="SELECT * FROM member_data";

     $mdSelectALL=mysql_query($mdSelectALL_sql,$mdConn);

     if(!$mdSelectALL){
            die('Error: ' . mysql_error());
     }
     else{
            echo "RETURNING ALL MEMBER DATA RECORDS!!!<br>";

            //store all records into array
            while($row=mysql_fetch_array($mdSelectALL))
            {


                    $this->mdId=$row['md_id'];
                    $this->mdFname=$row['md_fname'];
                    $this->mdLname=$row['md_lname'];
                    $this->mdEmail=$row['md_email'];
                    $this->mdTwitter=$row['md_twitter'];
                    $this->mdFacebook=$row['md_facebook'];
                    $this->mdMyspace=$row['md_myspace'];
                    $this->mdPhoneNumber=$row['md_phonenumber'];
                    $this->mdNotes=$row['md_notes'];



                    //store records in array
                    array_push($mdArray,$this);

           }//end while

           // print_r($mdArray); prints the array and each element is the last record  encountered in the SQL retrieval

            return $mdArray;

            }//end else

My getters and setters look like this for each property:

       function get_mdId(){
              return $this->mdId;
       }

       function set_mdId($id){
             $this->mdId=$id;
       }

And suggestions or ideas?

-TU

  • 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-14T12:42:01+00:00Added an answer on June 14, 2026 at 12:42 pm

    Objects are passed around by reference. That means that when you change a value, that value will change everywhere that you have used that object.

    As you are storing the same object every time – $this – you end up with an array of references to the same object.

    To solve it, you can do:

    $mdArray = array();
    while($row=mysql_fetch_array($mdSelectALL))
    {
       $tmp_object = new MyObject;   // fill in the name of your object...
    
       $tmp_object->mdId=$row['md_id'];
       ...
    
       array_push($mdArray, $tmp_object);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is probably a very simple fix to this, but i'm all new with
There is probably a very simple answer to this question, but I can't for
there is probably a very simple answer to this very simple question, but i
There is probably a very simple way of doing this, but this is a
There is probably a very simple solution to this but my jQuery skills are
There is probably a very simple answer to this, but I want to be
There's probably a very simple reason for this, but when hydrating an object I'm
There is probably a simple answer for this, but I couldn't find one, so
First of all there is probably a question like this already but i couldn't
I'm new to the OOP paradigm, so there's probably a simple explanation for this

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.