Re: need help with a table please - sorry

From: Date: Wed, 12 Feb 2003 15:05:07 +0000
Subject: Re: need help with a table please - sorry
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-135312@lists.php.net to get a copy of this message
At 15:43 12-2-03, you wrote:
Hello friends. Sorry I sent the wrong code in my last mail. Here is my correct code. I want the output of my query to be formatted such that after every 7th output, the 8th one should start on a new row in the table. I have written the following code but does not work. Can someone please help? Quote :
If you imagine to walk through your code, with every step $i increases. If you start the second row, Besides, your second print '<tr>' for every cell, which will break your table, and possibly other tables on your page.
<table width="800" border="0" cellspacing="0" cellpadding="3"> <tr>
      <?php
$i=0; while($row=mysql_fetch_array($result)){ $i=$i+1; if ($i==7){ Print "</tr><tr>"; Print"<td width=\"150\" >"; Print "<a href=\"findbycategory.php?"."CategoryId=".$row["CategoryId"] ."\"><font color=\"#000040\" size=\"2\">$row[CategoryName]</font></a>"." "; Print "</td>"; }else{ Print "<tr>"; Print"<td width=\"150\" >"; Print "<a href=\"findbycategory.php?"."CategoryId=".$row["CategoryId"] ."\"><font color=\"#000040\" size=\"2\">$row[CategoryName]</font></a>"." "; Print "</td>"; if ($i==6){ Print "</tr>"; }} } ?>
      <div align="center">&nbsp;</div></td>
</tr> </table>
Trying to keep as much from your code as possible: (not tested) <table width="800" border="0" cellspacing="0" cellpadding="3"> <tr> <?php $i=1; while($row=mysql_fetch_array($result)) {
        $i=$i+1;
        if ($i>7){ Print '</tr><tr>'; $i=1}
        Print '<td width="150" >'
                '<a href="findbycategory.php?CategoryId='.$row['CategoryId'] .'">'
                   .'<font color="#000040" size="2">'
                        .$row[CategoryName]
                   .'</font>'
                .'</a>    '
              .'</td>';
} // <div align="center">&nbsp;</div></td> // what was this for? //extra code to finish the row if total # of results is not dividible by 7 for (;$i<=7;$i++){echo '<td>&nbsp;</td>';} ?> </tr> </table> Note that i replaces double quotes with single quotes when possible.

« previous php.general (#135312) next »