カンマ区切りのテキストファイルに保存されている名前のリストから5列のhtmlテーブルを作成しようとしています。
私はここまで到達しましたが、有能なコーダーからはほど遠いので、助けが必要です。現時点では、1つの長い列にテーブルが表示されています。
<?php
$f = fopen("names.txt", "r");
while (!feof($f)) {
$arrM = explode(",",fgets($f));
$val = current ( $arrM ) ;
print "<table border=1>";
while ( $val )
{
print "<tr> <td> $val </td> ";
$val = next ( $arrM) ;
print "<td> $val </td> </tr> ";
print "\n";
$val = next ( $arrM );
}
print "</table>";
}
?>
よろしくお願いします
解決済み...同じヘルプを探しているGoogle社員のコードは次のとおりです。
<?php
$tdcount = 1; $numtd = 3; // number of cells per row
print "<table>";
$f = fopen("names.txt", "r");
while (!feof($f)) {
$arrM = explode(",",fgets($f));
$row = current ( $arrM );
if ($tdcount == 1)
print "<tr>"; print "<td>$row </td>";
if ($tdcount == $numtd) {
print "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
print "<td> </td>"; $tdcount++;
} print "</tr>";
}
print "</table>";
?>