Forum Moderators: coopster

Message Too Old, No Replies

Little table help please!

5 colums only.

         

PokeTech

11:57 pm on Jun 7, 2008 (gmt 0)

10+ Year Member



I have a table that looks like this:

[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]

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]

webfoo

12:50 am on Jun 8, 2008 (gmt 0)

10+ Year Member



A little more info please? Make sure that </tr> comes after each DB reccord.

PokeTech

11:31 am on Jun 8, 2008 (gmt 0)

10+ Year Member



Here's the code i'm using:

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.

[][][][][]
[]

barns101

3:44 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



Some code I use, which you can modify to suit your needs:

<?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>&nbsp;</td>\n";
$tdcount++;
}
echo "</tr>\n";
}
echo "</table>\n";
?>

jatar_k

4:07 pm on Jun 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from our library
[webmasterworld.com...]

PokeTech

4:32 pm on Jun 8, 2008 (gmt 0)

10+ Year Member



Great, thanks! That worked.

barns101

11:07 am on Jun 9, 2008 (gmt 0)

10+ Year Member



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. :)

jatar_k

11:34 am on Jun 9, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, no worries, I didn't even notice it was the same until after I posted it ;)

coopster

2:02 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Not trying to pass it off as my own work

That's the beauty of sharing in these forums! It was offered freely to be used freely. As jatar_k just said, no worries! I pass off plenty of his code snippets as my own :)

PokeTech

2:14 pm on Jun 9, 2008 (gmt 0)

10+ Year Member



*laughs* haha!