Jump to content

getting objects from array of database results


silphium

Recommended Posts

How do I access objects inside an array of database results? I have a method that returns MySQL results as an array "$projects". Running print_r($projects) gives me this:

 

array(1) (

    "projects" => object Database_MySQL_Result(6) {

        protected _internal_row => integer 0

        protected _query => string(875) "SELECT [skipping remainder of long query]"

        protected _result => resource(mysql result)

        protected _total_rows => integer 53

        protected _current_row => integer 0

        protected _as_object => string(13) "Model_Project"

    }

)

 

If I do this: foreach($projects as $project)

{

echo $project->PROJECT_NAME;

}

 

I get "Undefined property: Database_MySQL_Result::$PROJECT_NAME"

 

If I do this:

 

foreach($projects as $project)

{

echo $project[0];

}

 

the browser will display projects.id for the first returned row *only*

 

echo $project[1] returns the project.id for the second row only. And so on.

 

Each returned row contains over a dozen cells.

 

It's almost as if I'm referring to the array incorrectly, or referring to the wrong array. I feel as though I'm making a very simple (and perhaps dumb) mistake here, but can't quite figure out what it is. Thanks.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.