如何将表格的行格式化为2列 [英] How to format table rows into 2 columns

查看:215
本文介绍了如何将表格的行格式化为2列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅,如果这个问题是基本的 - 相当新的使用MySQL。我遗漏了下面的代码中的查询和循环/引用,因为我的问题是格式化表。 (我希望信息是不需要的)

现在下面的代码的结果是在单个表格行中显示的信息跨越表格的宽度,这些行继续,直到显示所有数据。



我如何格式化这个,而不是一个表格行中的一个长单元格,我得到每个表格行两个单元格?

我无法弄清楚这是将表格格式化为2列还是格式化tr或td。

非常感谢您的帮助和指导!!

  echo('< table width =85%align =centercellspacing =15>'); 
//查询,循环,引用

echo('< tr>
< td bgcolor =#ddddddstyle =border:1px solid#000000; padding :12px>
< div style =float:right>
< form action =index.phpmethod =get>
< input type =hiddenname =pagevalue =viewproject>
< input type =hiddenname =projectidvalue ='.projectid。'>
< ; input type =submitvalue =View Event>< / form>
< br>
< form action =jump_delete.phpmethod =postalign =
< input type =hiddenname =projectidvalue ='。$ projectid。'>
< input type =submitvalue =Delete >< / form>
< / div>
< div style =font-weight:bold; font-size:18px>'。$ projectclien T< / DIV>
< div style =font-size:15px>< b>事件:< / b> $项目名称。< / DIV>
< div style =font-size:15px>日期:'。$ duedateformatted。'< / div>
< div style =font-size:15px>员工数:'。$ projectstaffcount。'< / div>
< / td>
< / tr>');

更新:使用我自己版本的帮助来到一个答案,为我完成这项工作。感谢所有帮助和建议!!!

  if($ i%2 == 1){
if($ i!= 0){
echo('< / tr>);
}


解决方案

strong>表示基本上是单元格或列的表数据
$ b tr 代表表格行

您的 tr 内的 td 的数量将决定您将要获得的列数。

另外,看看td属性 colspan rowspan 这里



在您的具体情况下,我的猜测是您想在表中添加另一个td

 < table width =85%align =centercellspacing =15> 
< tr>
< td bgcolor =#ddddddstyle =border:1px solid#000000; padding:12px>< / td>
< td bgcolor =#ddddddstyle =border:1px solid#000000; padding:12px>< / td>
< / tr>
< / table>

更新:像这样

  echo'< table width =85%align =centercellspacing =15>' ; 
echo'< tr>';
$ i = 0;
while(...){
//跳过第一个迭代
//然后在每一秒之后< td>关闭< tr>如果($ i> 0和$ i%2 == 0){
echo'< / tr>< tr>',则打开新的
;

echo'< td bgcolor =#ddddddstyle =border:1px solid#000000; padding:12px>< / td>';
$ i ++;
}
echo'< / tr>';
echo'< / table>';


Please excuse me if this question is elementary - fairly new to working with mysql. I left out the query and loop/references in the code below, because my question is on formatting the table. (I hope that info isn't needed)

Right now the result of the code below is the info being displayed in one single table row that spans the width of the table, these rows continue until all data is displayed.

How can I format this so instead of one long cell in one table row, I get two cells per table row?

I haven't been able to figure out if this is a matter of formatting the table into 2 columns or formatting the tr or td.

Thank you very much for your help and guidance on this!!

echo('<table width="85%" align="center" cellspacing="15">');
//query,loop, references

   echo('<tr>
      <td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px">
         <div style="float:right">
            <form action="index.php" method="get">
                                <input type="hidden" name="page" value="viewproject">
                                <input type="hidden" name="projectid" value="'.$projectid.'">
                                <input type="submit" value="View Event"></form>
                        <br>
                <form action="jump_delete.php" method="post" align="right">
                                <input type="hidden" name="projectid" value="'.$projectid.'">
                                <input type="submit" value="Delete"></form>
         </div>
         <div style="font-weight:bold; font-size:18px">'.$projectclient.'</div>
            <div style="font-size:15px"><b>Event:</b> '.$projectname.'</div>
            <div style="font-size:15px">Date: '.$duedateformatted.'</div>
            <div style="font-size:15px">Staff Count: '.$projectstaffcount.'</div>
      </td>
    </tr>');

UPDATE: With using my own version of the help from below - I came to an answer that gets the job done for me. Thanks to all who chimed in with help and advice!!! Using an if statement to create when new rows happen.

if($i % 2 == 1) {
   if($i != 0) {
        echo(‘</tr>');
    }

解决方案

td means table data which is basically a cell or column

tr stands for table row

The number of td inside your tr will determine how many columns you are going to get.

Also, have a look at the td attribute colspan and rowspan here

In your specific case my guess is that you want to add another td inside your table

<table width="85%" align="center" cellspacing="15">
    <tr>
        <td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>
        <td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>
    </tr>
</table>

UPDATE: to loop through your data you need something like this

echo '<table width="85%" align="center" cellspacing="15">';
echo '<tr>';
$i = 0;
while(...) {
    // skip the first iteration
    // then after every second <td> close the <tr> and open a newone
    if($i > 0 and $i % 2 == 0) {
        echo '</tr><tr>';
    }
    echo '<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>';
    $i++;
}
echo '</tr>';
echo '</table>';

这篇关于如何将表格的行格式化为2列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆