formatting - Dynamically generate table using PHP -
i know has been asked before , have got working using following code:
<?php $maxcols = 8; $i = 0; echo "<table id='table1'><tr>"; foreach ($id $k => $v) { echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++; if ($i == $maxcols) { $i = 0; echo "</tr><tr>"; } } $i++; while ($i <= $maxcols) { $i++; echo "<td></td>"; } echo "</tr></table>"; ?> this results in table looks :

i'd add headers end result looks this:

i'd dynamically if create table 5 columns wide i'd on first header row id01 - id05 , on second header row id06 - id10
i want limit header id values no more $maxid header fields should blank, : if $maxid = 12; :

i need header rows made follows , not using <th>
<td class="mark"> i'm using javascript allow movement of cell data.
the class used set formatting on header , stop items being dragged fields.
can point me in right direction on how this.
this should you.
$maxcols = 8; $maxid = 12; $startid = 1; echo "<table id='table1'>\n"; ($i = 1;$i<=ceil($maxid/$maxcols);$i++) { echo "<tr>\n"; ($j=1;$j<=$maxcols;$j++) if ($startid <= $maxid) echo " <td class='mark'>id".$startid++."</td>\n"; else echo " <td> </td>\n"; echo "</tr>\n<tr>\n"; ($j=1;$j<=$maxcols;$j++) echo "<td>content</td>\n"; echo "</tr>\n"; } echo "</table>\n"; generates
<table id='table1'> <tr> <td class='mark'>id1</td> <td class='mark'>id2</td> <td class='mark'>id3</td> <td class='mark'>id4</td> <td class='mark'>id5</td> <td class='mark'>id6</td> <td class='mark'>id7</td> <td class='mark'>id8</td> </tr> <tr> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> </tr> <tr> <td class='mark'>id9</td> <td class='mark'>id10</td> <td class='mark'>id11</td> <td class='mark'>id12</td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> <td>content</td> </tr> </table>
Comments
Post a Comment