0

2 つの for ループを出力する 10*10 の固定テーブルがあります。一部の画像はtable cell、管理者から指定された行 ID と列 ID に一致する特定のウィッチに表示されます。

$table .= '<table border="1" cellspacing="0" cellpadding="2" class="banner_table">';
    for($x=1; $x<=10; $x++) {
       $table .= "<tr>";
       for($y=1; $y<=10; $y++) {
           $table .= "<td class='thumbnail'>";

                if (isset($temp[$x][$y])) {
                    $count++;  
                    $table .= "<a target='_blank' href='" . ($temp[$x][$y]['img_url'] ? $temp[$x][$y]['img_url'] : "#") . "'>
                    <img id='imgid' src='admin/small-image/" . $temp[$x][$y]['img_title'] . "' width='20' height='20' /></a>";                   
                }  
           else $table .="&nbsp;";
           $table .= "</td>"; 
        }
        $table .= "</tr>";
   }
   $table .= '</table>';

row id与えられていないテーブルセルに 1,2,2... などのインデックス番号を指定するにはどうすればよいcolumn idですか? 同様に、インデックス番号 1 (ROW 1 AND COL1)、インデックス番号 2 (ROW1 および COL2) を指定します。

行IDと列IDから表のセル番号を取得する方法はありますか?

4

1 に答える 1

2
// Index number to row and column:
$index_no = 13; // Number from 1 to 100
$y = floor(($index_no-1)/10)+1;
$x = $index_no-($y-1)*10;

// Row and column to index number:
$x = 4;
$y = 3;
$index_no = ($y-1)*10+$x; // Number from 1 to 100
于 2013-07-09T18:10:48.950 に答える