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.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to