php - Accessing Multidimensional stdClass array in Codeigniter -


I think that's a special case I think my array is so far away that traditional to reach a stdClass Ways are not working.

Before anyone postes me on this subject (which are many), I ding for not checking that I want to post that I have examined almost all of them and here There are some links to prove this.

I have read them all. I have tried all the suggestions to access the data. None of them are working for the day

My data is formatted in this form:

  child :: __set_state (array ('id' = & gt; ; NULL, 'code' = & gt; NULL, 'accld' = & gt; NULL, 'fname' = & gt; null, 'mname' = & gt; null, 'lname' = & gt; null, 'gender '= & Gt; Faucet,' dub '= & gt; Faucet,' class '= & gt; zero', 'picture' => Faucet, 'allergy' => Faucet, '0' => ; StdClass :: __set_state (array ('id' = & gt; '1039', 'zero' 'code' => '2383', 'accId' => '32', 'fname' = & 'L', 'lname' = & gt; gender '=' 2 ',' dub '=>' 2005-10 ',' class', 'lorraine', 'mname' => '= & Gt; 1', 'condition' = & gt; '1', 'photo' = & gt; ',' allergy '= & Gt; '', ')),' 1 '=> stdClass :: __set_state (array (' id '=>' 1044 ',' code '=>' 6266 ',' accId '= & '32', 'fname' = & gt; Justin ',' mname '= & gt;' R ',' lname '= & gt;' cings', 'gender' = & gt; '1' 'Dob' = & gt; ', 2001' ',' class '=>' 15 ',' condition '=> 11', 'photo' =>, 'allergy' = & gt; My personal opinion is that my data needs to be formatted  
  [0] = & gt; StdClass :: __set_state (array (.....   

) because when I look at all the other posting arrays, the array number contains a list of single quotation marks.

In my model code, this is what is generating the array:

  public function populate ($ line) {foreach ($ line as line $ => gt; ; $ Value) {$ this-> $ Key = $ value}}   

In this theory, the only thing to poke a hole is because I have another array This is generated by this same function and it can evaluate its values ​​by $ myarray-> Value.

Thanks for watching and viewing your thoughts.

Answer

I responded with this puzzle that I had to go back and change my model code.

From this:

  Public function accld ($ id) {$ query = $ this-> db- & gt; get_where ($ this :: DB_TABLE, array ('accId = & gt; $ id)); $ result = $ this- & Gt; Populate ($ query- & gt; result ()); return result;}   

To do this:

  public function accld ($ id) {$ query = $ this- & gt; Db- & gt; Get_where ($ this :: db_TABLE, array ('accId' = & gt; $ id)); $ Result = $ this- & gt; Populate ($ query-> result ('array')); Return result; }   

Adding the 'array' argument changed the data received from

  children :: __set_state ( Array ('id' = & gt; NULL, 'code' => NULL, 'accld' => NULL, 'fname' = & gt; null, 'mname' = & gt; null, 'lname' = & Gt; NULL, 'gender' = & gt; faucet, 'dub' => Faucet, 'class' => Faucet, 'position' => Faucet, 'photo' = & gt; null , 'Allergy' = & gt; NULL, 0 '' => array ('id' => 1161 ',' code '=>' 1784 ',' accId '=>' 124 ',' Fname '= & gt; Diane,' Mama '= & gt;' ',' lname '=>' Greene ',' gender '=> 1', 'dob' = & Gt; '2012-6', 'class' = & gt;' 18 ',' condition '= & gt; 7', 'photo' =>);   

Then I can write it once again via this

  foreach ($ $ as key => $ val) {if (empty ($ val)) {  

However, you know how it's working, I'm not sure you understand That's why. Codeigniter returns an array of objects unless you specify it to return, for example if you want

  $ result = array (array ('id' = & gt; ; 1, 'name' = & gt; Like an array is received) Steve ',' age '= & gt; 22)); Without using the 'array' argument, without it the standard code can be accessed in its default format with the Igniter Return Object Node, for example - for example - you will use the name in the first result row. This  
  $ name = $ result [0] - & gt; Name;   

I hope that makes sense and makes it a bit clearer for you.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -