문제

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