如何将表格的行格式化为2列 [英] How to format table rows into 2 columns
问题描述
现在下面的代码的结果是在单个表格行中显示的信息跨越表格的宽度,这些行继续,直到显示所有数据。
我如何格式化这个,而不是一个表格行中的一个长单元格,我得到每个表格行两个单元格?
我无法弄清楚这是将表格格式化为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>);
}
您的 tr 内的 td 的数量将决定您将要获得的列数。 另外,看看td属性 colspan 和 rowspan 这里 在您的具体情况下,我的猜测是您想在表中添加另一个td 更新:像这样 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!! 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.
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 UPDATE:
to loop through your data you need something like this
这篇关于如何将表格的行格式化为2列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b tr 代表表格行
< 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>';
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>');
if($i % 2 == 1) {
if($i != 0) {
echo(‘</tr>');
}
<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>
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>';