はい、どうぞ:
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
if ($i % 12 == 0) {
// Table ID dont need to be rounded, because $i % 12 == 0, so $i / 12 is integer, not float...
echo '<table id="Table'.($i / 12 + 1).'">'."\n";
}
if ($i % 3 == 0) {
echo '<tr>'."\n";
}
echo '<td>'.$row['name_file'].'</td>'."\n";
if ($i % 3 == 2) {
echo '</tr>'."\n";
}
if ($i % 12 == 11) {
echo '</table>'."\n";
}
$i++;
}
if ($i % 3 > 0) {
echo '</tr>'."\n";
}
if ($i % 12 > 0) {
echo '</table>'."\n";
}
}
Fe は、name_file = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 があるとしましょう。次に、これを出力します:
<table id="Table1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>
<table id="Table2">
<tr>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
<tr>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
<tr>
<td>19</td>
</tr>
</table>