I would like to print out a html table- it should divide data into x columns per row via for loop.

$alphabet_arr = array('A','B','C','D','E','F','G','H','I','J','K');

No. of cols need to define, eg: cols= 3

No. of rows define as unlimited for now (so that whatever data excess cols will be push down to new tr, future may allow define specific row.

Then inside the table, it should be like this

table start
1st tbl row showing A, B, C
2nd tbl row showing D, E, F
3rd tbl row showing G, H, I
4th tbl row showing J, K, empty td
table end
有帮助吗?

解决方案

print <table>
row_num = arr_size/col_size;
if (arr_size % col_size != 0) row_num++;
for (int i=0; i<row_num; ++i)
{
   print <tr>
   for (int j=0; j<col_size; ++j)
   {
      print <td> arr[i*col_size+j] </td>
   }
   print </tr>
}
print </table>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top