php - Laravel Undefined index Error in array values display -


i using laravel 4.2. have 2 mysql tables owntable, othertable. getting values these tables through php.

my further php code below display values in blade php,

if (!empty ($owntable)){             foreach($owntable $owntbl){                 $finalvalue['ownvalue']['name'] = $owntbl->name;             }         } if (!empty ($othertable)){             foreach($othertable $othertbl){                 $finalvalue['othervalue']['name'] = $othertbl->name;             }         }   $mydata = array('finalvalue' => $finalvalue);  if(.....) {     return view::make('display')->with('mydata', $mydata);  } 

and code in display.blade below,

            <tbody>                      @foreach($mydata['finalvalue'] $res)                     <tr>                         <td>{{{$res['ownvalue']['name']}}}</td>                         <td>{{{$res['othervalue']['name']}}}</td>                      </tr>                 @endforeach                  </tbody>   

when try run code, gives error 'undefined index: ownvalue'.

i sure doing mistakes in array handling. not talent in array handling. highly appreciate if suggest me in this. :-)

as rule of thumb, use var_dump debug , see how arrays @ different places within code. example can see $res inside foreach loop in view , see why have undefined indices.

overall code looks little more complicated should be, put on side. uou setting different values same key, add empty brackets indicated going push new values array:

foreach($owntable $owntbl){     $finalvalue['ownvalue']['name'][] = $owntbl->name; } 

you can use old keys (if matter):

foreach($owntable $key => $owntbl){     $finalvalue['ownvalue']['name'][$key] = $owntbl->name; } 

note blade needs 2 pairs of curly brackets in view (currently have 3 pairs).

so yeah, track down state of arrays using var_dump , find things go wrong.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -