Forum Moderators: coopster
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
How do I get it to look like this:
[][][][][]
[][][][][]
[][][][][]
[][][][][]
[][][][][]
Cause I'm drawing information from a sql and I'm putting it into a table and I want it to have 5 columns and not like 50... How do I fix that.
[edited by: PokeTech at 11:58 pm (utc) on June 7, 2008]
echo <<<html
<table width="100%">
<tr>
html;
$query = "SELECT * FROM pokedex_sprites WHERE pid='$sprites'";
$result = mysql_query($query);
while($sprites = mysql_fetch_assoc($result)){
echo <<<html
<td class="site-tborder" border="1" width="10%">
<center><img src="{$sprites['image']}"><br>
By: <a href="/forum/member.php?action=profile&uid={$sprites['uid']}" target="_blank">{$sprites['username']}</a></center>
</td>
html;
}
echo <<<html
</tr>
</table>
</td></tr>
<tr>
<td>
html;
I'm drawing information from the database and placing it into a table but the table is turning out like this:
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
Isntead I want it to look like this:
[][][][][]
[][][][][]
[][][][][]
[][][][][]
[][][][][]
so whenever there is 5 <td></td>'s in a row then it jumps down and starts another row.
[][][][][]
[]
<?php
mysql_connect("localhost", "user", "pass");
mysql_select_db("database");$result = mysql_query("SELECT * FROM `table`");
$tdcount = 1;
$numtd = 5; // number of cells per row
echo '<table border="0" cellpadding="0" cellspacing="0">';
while($row = @mysql_fetch_array($result))
{
if ($tdcount == 1) echo "<tr>\n";
echo "<td>$row[whatever]</td>\n";
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td> </td>\n";
$tdcount++;
}
echo "</tr>\n";
}
echo "</table>\n";
?>
from our library
[webmasterworld.com...]I had a feeling that I may have got it from here originally. Not trying to pass it off as my own work, jatar_k. :)