将数组放入 html 表中

发布于 2024-12-20 13:06:16 字数 1020 浏览 0 评论 0原文

$result 实际上是一个数组,如下所示:

Array ( [book_title] => 21 世纪的生物伦理学 [id] => 1424 [isbn] => 978-953-307-270-8 [unix_name] => 21 世纪的生物伦理学 [visible_online] => 1)

这是我的观点(更好地说......观点的糟糕尝试)。我正在尝试根据数组的索引进行对齐。就像这样: 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>

感谢您的帮助!

$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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奈何桥上唱咆哮 2024-12-27 13:06:16

你正在尝试这样做吗?

<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>

作为旁注,应避免 语法,因为 short_open_tag 在许多 PHP 安装中被禁用,并且在 PHP 5.4.0 之前需要使用该语法

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

浅语花开 2024-12-27 13:06:16

取决于您如何从数据库中获取结果,它将是这样的:

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

或者如果您使用的是学说:

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

您应该阅读教程,其中包含类似的内容:)
http://framework.zend.com/manual/en/zend.db .statement.html

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

请持续率性 2024-12-27 13:06:16
...
    <tbody>
            <?php foreach($this->basicBwDetails as $result): ?>
            <tr>    
               <?php foreach($result as $cell)?>
                  <td><?=$cell;?>  </td>
               <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>

        </tbody>
...

像这样 ?

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

        </tbody>
...

Like this ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文