php - 重新设计页面 : changing the PHP code that generates the HTML

标签 php html css

<分区>

我正在尝试重新设计一个 Web 应用程序,但我被这段代码难住了:

foreach ($this->cells1 as $c) {
            $s .= $c[2] ? $c[2] : '';
            $s .= '<div style="clear:both"><table><tr><td nowrap="nowrap"' . ($c[0] ? (' ' . $c[0]) : '') . '>';
            $s .= $c[1] ? $c[1] : '&nbsp;';
            $s .= '</td>';
            $s .= $c[3] ? $c[3] : '';
        }
        $s .= '</tr></table></div>';

它正在生成 HTML 代码,例如:

<div style="clear:both"></div>
<table>
   <tbody>
      <tr>
        <td nowrap="nowrap">Search:</td>
        <form action="some-action" method="post"></form>
      </tr>
   </tbody>
 </table>

 <div style="clear:both"></div>
 <table>
   <tbody>
      <tr class="alt-row">
        <td nowrap="nowrap">
          <input type="text">
        </td>
      </tr>
   </tbody>
 </table>

 <div style="clear:both"></div>
 <table>
   <tbody>
     <tr>
       <td nowrap="nowrap">&nbsp;</td>
       <form action="some-action" method="post"></form>
     </tr>
   </tbody>
 </table>

and so on. . . .

它看起来像这样:

Disregard the size of the buttons. That's intentional

我只想将它们全部放在一个 div 中,我可以根据自己的喜好设计样式。任何人都可以向我解释那部分代码,以便我可以使用它吗? 或者更好的办法是告诉我另一种方法让它们适合 div。

最佳答案

您需要澄清您的问题以提及您希望删除表结构。

这里发生的事情是应用程序为该数组中的每个元素返回一个数组 $this->cells1 它正在使用它包含的元素创建一个单独的表。

下面是一个三元 if 语句,它说的是 if c[2] exists echo c[2] if not echo '' 该行的第一件事是问题,然后是问号,如果问题是正确的,然后是冒号,如果问题是错误的,该怎么办。

$c[2] ? $c[2] : '';

要将其更改为只创建 div,您真正需要做的就是删除表格标记并将其替换为您需要的任何内容。

例如:

foreach ($this->cells1 as $c) {
            $s .= $c[2] ? $c[2] : '';
            $s .= '<div><p>' . ($c[0] ? (' ' . $c[0]) : '');
            $s .= $c[1] ? $c[1] : '&nbsp;';
            $s .= '</p>';
            $s .= $c[3] ? $c[3] : '';
        }
        $s .= '</div>';

将生成一个第一个元素包含在 p 标签中的 div。

就我个人而言,我会做的是分别回显每个元素以查看它返回的内容,然后相应地构造 foreach,因为老实说它看起来也有一些从数据库返回的 HTML。

foreach($this->cells1 as $c) {

    echo 'c0:' . $c[0];
    echo 'c1:' . $c[1];
    echo 'c2:' . $c[2];
    echo 'c3:' . $c[3];
}

这将为您提供每个元素返回的内容的列表,这样您就可以弄清楚数据的样子,在您知道弄清楚如何处理它会让生活变得更轻松之后。

关于php - 重新设计页面 : changing the PHP code that generates the HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15473793/

上一篇:jquery - 在打印时隐藏调整大小功能

下一篇:Css float 位置

相关文章:

javascript 懒加载的渐进增强方式?

html - CSS/HTML 不透明度

ios - 在为 Cordova iOS 应用程序构建 Appium 测试框架时寻找选择器的任何更简单的方法

jquery - 使用 JQuery Mobile CSS 设置 JQuery 创建按钮的样式?

javascript - JQuery Mobile OSM div 自动设置为 0% 高度,即使我的 CSS 已将其设置为 100%

php - 在 Web 应用程序中处理具有 "has many"关系的数据更新

php - 在带有 mysql 的 php 中,您可以将 $var 替换为 :var?

javascript - 使用 jquery 显示和隐藏菜单

php - 如何从数据库中获取NULL

php - 在 MySQL 中将多个项目链接到单个项目的最佳方法