Jump to content

dynamic table generation??


feri_soft

Recommended Posts

How dynamically to generate a table like this:

I have 22 subcategories in mysql i open a main category and i want all the subs to be shown in the page but formated as a table, not simple <br>
Like;

adasd                                asdasdasd                              asdas
asdasda                            adasdasdasd                            asdasda
adasdasd                            adasdasd
asdasd                              adasdasd

I cant figure out a way because the number of subcats for each category is not fixed.  And there are categories with only 2-3 subs....

Please help!
Link to comment
https://forums.phpfreaks.com/topic/33116-dynamic-table-generation/
Share on other sites

I'm just guessing your table structure here...
[code=php:0]
echo "<table>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";

//If previous cat isn't the same as this one, echo it.
if($catcache != $row['cat']) echo $row['cat'];

echo "</td><td>";
echo $row['subcat'];
echo "</td></tr>";
$catcache = $row['cat'];
}
echo "</table>";[/code]

If your SQL table isn't setup like I assumed, post an example of it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.