1

$result is actually an array which looks like this:

Array ( [book_title] => Bioethics in the 21st Century [id] => 1424 [isbn] => 978-953-307-270-8 [unix_name] => bioethics-in-the-21st-century [visible_online] => 1 )

This is my view(better said...poor attempt of a view ). I'm trying to get an alignment based on the index of the array. Like so: http://pastebin.com/z13PZWe8

<table class="datagrid grid_collapsible" width="100%" cellpadding="2" cellspacing="0" id="webbooks_table">
            <thead>
    <tr class="datagrid_header"
        <td>Book title</td>
        <td>ID</td>
        <td>ISBN</td>
        <td>Is it visible online?</td>
    </tr>
        </thead>

    <tbody>
        <?php foreach($this->basicBwDetails as $result): ?>
        <tr>    
    <td><?=$result;?>  </td>
        </tr>
        <?php endforeach; ?>

    </tbody>



</table>

Thank you for your help!

3 Answers 3

1

Are you trying to do this?

<table class="datagrid grid_collapsible" width="100%" cellpadding="2" cellspacing="0" id="webbooks_table">

  <thead>
    <tr class="datagrid_header">
      <td>Book title</td>
      <td>ID</td>
      <td>ISBN</td>
      <td>Is it visible online?</td>
    </tr>
  </thead>

  <tbody>
<?php foreach($this->basicBwDetails as $result): ?>
    <tr>    
      <td><?php echo $result['book_title']; ?></td>
      <td><?php echo $result['id']; ?></td>
      <td><?php echo $result['isbn']; ?></td>
      <td><?php echo ($result['visible_online']) ? 'Yes' : 'No'; ?></td>
    </tr>
<?php endforeach; ?>
  </tbody>

</table>

As a side note, <?=$var;?> syntax should be avoided since short_open_tag is disabled in many PHP installations, and this was required to use that syntax until PHP 5.4.0

Sign up to request clarification or add additional context in comments.

1 Comment

@DaveRandom - you don't echo on iteration. <?php $result['book_title']; ?> won't show anything.
1

Depends on how You got the result form database it will be something like this:

<td><?=$result['book_title']?>  </td>
<td><?=$result['id']?>  </td>
<td><?=$result['isbn']?>  </td>
<td><?=$result['visible_online']?>  </td>

Or if You're using doctrine:

<td><?=$result->book_title?>  </td>
<td><?=$result->id?>  </td>
<td><?=$result->isbn?>  </td>
<td><?=$result->visible_online?>  </td>

You should read tutorial, things like that are in it :) http://framework.zend.com/manual/en/zend.db.statement.html

1 Comment

Please don't get offended your answer was also useful. Thank you!
0
...
    <tbody>
            <?php foreach($this->basicBwDetails as $result): ?>
            <tr>    
               <?php foreach($result as $cell)?>
                  <td><?=$cell;?>  </td>
               <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>

        </tbody>
...

Like this ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.