userK1400 userK1400 - 4 months ago 7x
HTML Question

How to format table rows into 2 columns

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

<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>
<form action="jump_delete.php" method="post" align="right">
<input type="hidden" name="projectid" value="'.$projectid.'">
<input type="submit" value="Delete"></form>
<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>

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


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">
        <td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>
        <td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>

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>';
echo '</tr>';
echo '</table>';