Displaying data from array to a particular form field in codeigniter view

This is array I am getting by storing multiple values in a table

         Array
 (
    [sen] => Array
    (
        [0] => stdClass Object
            (
                [id] => 1
                [sen_id] => 8
                [no_of_years] => 1
                [no_of_leaves] => 2
            )

        [1] => stdClass Object
            (
                [id] => 2
                [sen_id] => 8
                [no_of_years] => 2
                [no_of_leaves] => 3
            )

       )

  )

I want to show the value of no_of_years and no_of_leaves in a form field which is like below

                         <div class="col-md-4">
                         <input type="text" name="no_of_years[]"  class="form-control name_list"  value="<?php echo $sen[0]->no_of_years;?>"/>
                      </div>
                        <div class="col-md-4">
                           <input type="text" name="no_of_leaves[]" class="form-control name_list" value="<?php echo $sen[0]->no_of_leaves;?>"/>
                       </div>

but its not working , How can I fix it?

What did you var_dump() to get the first list? There seems to be an additional Array keyword there. I’d sort of expect something like

echo $array['sen']['0]'->no_of_leaves;

though I’m not near a machine to test.

I was already getting the [sen] array but to show in view I fetched it from model and store it in a variavle in view and I print that using print_r(Ssenior ); and got the output like above array structure

Ah, so shouldn’t it be

echo $Ssenior['sen'][0]->no_of_leaves;

its not working , Where I am going wrong ?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.