rafiq
rafiq

Reputation: 81

How to list rows individually when using in controller not view

On the view if i post like this it works, but i want each column individually in this controller. i can do this on first foreach but on second one i want how to do that when i am using $field_name - what code do i need to add to this?

    <?php foreach($formates as $formate): ?>
    <tr>
        <?php foreach($fields as $field_name => $field_display): ?>
        <td>
            <?php echo $formate->$field_name(HERE i want individualy ?>
        </td>
        <?php endforeach; ?>
    </tr>
    <?php endforeach; ?>

controller

$data['fields'] = array(
    'FID' => 'ID',
    'title' => 'Title',
    'category' => 'Category',
    'dep_id' => 'Department',
    'bf_linkpdf' => 'pdf',
    'bf_linkxls' => 'xls',
    'bf_linkdoc' => 'doc'
);

on the view i want to list them indevidualy

    <?php foreach($formates as $formate): ?>
<tr>
    <?php foreach($fields as $field_name => $field_display): ?>
    <td>
        <?php echo $formate->$field_name->FID ?>
            <?php echo $formate->$field_name->title ?>
            <?php echo $formate->$field_name->category ?>
            <?php echo $formate->$field_name->dep_id ?>
    </td>
    <?php endforeach; ?>
</tr>
<?php endforeach; ?>

regards thanks in advance.

Upvotes: 1

Views: 70

Answers (2)

rafiq
rafiq

Reputation: 81

On the view I added the following and it started working.

           <?php foreach($formates as $formate): ?>
        <tr>
                <td><?php echo $formate->id; ?></td>
            <td><?php echo $formate->title; ?></td>
            <td><?php echo $formate->category; ?></td>
            <td><?php echo $formate->dep_id; ?></td>
        </tr>
       <?php endforeach; ?>

Upvotes: 1

bipen
bipen

Reputation: 36541

i don't know why are you using the first loop formats , since your array is field..you can just do

<?php foreach($fields as $field): ?>
<td>
    <?php echo $field['FID'] ?>
        <?php echo $field['title'] ?>
        <?php echo $field['category'] ?>
        <?php echo $field['dep_id'] ?>
</td>
<?php endforeach; ?>

OR

each fields name and display in each <tr>

<?php foreach($fields as $field_name => $field_display): ?>
<tr>
 <td>
    <?php echo $field_name ?>
</td>
<td><?php echo $field_display ?></td>
</tr>
<?php endforeach; ?>

Upvotes: 0

Related Questions