Jump to content

Methods missing after returning array of objects


kovudalion

Recommended Posts

Ok, i have a bit of a quandry.... I am using one file to access my database and create an array of objects then pass that array back to my application controller Index.php using the return function. When the array gets back to the controller I unspool it using a foreach loop to get each object element out of the array but all my methods are unaccessible from the foreach element... I have enclosed samples of the offending code and a copy of the vardump of one of the elements... Any help would be appreciated.

 

 

LK

 

(Database query code and creation of the array)

 

---------------------------------------------------------

 

public function query_db($query)

{

    $processedquery = array();

    $query_results = mysql_query($query);

 

    if (is_resource($query_results))

      {

        $this->translog[] = "db query successfull";

        while ($row = mysql_fetch_array($query_results, MYSQL_ASSOC))

            {

                $processedquery[]=new Obj_quotes($row[*quote*], $row[site]); \\ stars added around word QUOTE to avoid message board processing as a quote (it is not that way in my code)

                //var_dump ($processedquery);

            }

        return ($processedquery);

      }

      else

        {

          $this->translog []= "Query $query failed to process";

          return FALSE;

        }

}

 

 

 

---------------------------------------

 

(Processing the array in Index.php)

 

 

--------------------------------------

                    $selectquote = rand(1,$database_connector->table_row_count("SELECT * FROM quotes q"));

                    $returned_query_data =  $database_connector->query_db("SELECT q.`quote`, q.`site` FROM quotes q where q.`index`=$selectquote");

                    if (($returned_query_data!=FALSE)&&($returned_query_data!=NULL))

                        {

                            foreach ($returned_query_data as $datarow)

                                {

                                    var_dump($datarow);

                                    //echo "Quote-$datarow->get_quote()  Site-$datarow->get_site()<br>";

                                }

                        }

                        else

                            {

                                show_error_page($database_connector->show_transaction_log());

                            }

 

 

---------------------------------------------------------------------------

 

(Var_Dump of element after being pulled out of the array using foreach)

 

 

--------------------------------------------------------------------------

object(Obj_quotes)#2 (2) { ["quote:private"]=> string(133) "Hes a ten month old male who called on the day of admission to complain that his asthma was worse and he still has left otitis media." ["site:private"]=> string(91) "http://www.nursinghumor.com/humor/medical.doctor.physician.patient.jokes.chart.bloopers.htm" }

 

 

You need to include the class file to gain access to the methods. A serialized object is just a serialized copy of the object properties without that.

 

The code I was showing is just SNIPPETS ...the obj_quotes.php file is listed as an include

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.