0
我有10 * 10固定表格打印兩個for循環。 某些圖像在某些給定的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 .=" ";
$table .= "</td>";
}
$table .= "</tr>";
}
$table .= '</table>';
我應該如何給索引號,如1,2,2 ......爲表單元格沒有給出row id
和column id
?我想給索引號1(行1和COL1),索引號2(行1和COL2)同樣。
是否有任何方法從行ID和列ID獲取表格單元號?
爲了在第一種情況下獲得$ x,我認爲先獲得$ y然後減去$ y * 10到$ index_no會更快。即 '$ y = floor(($ index_no-1)/ 10)+1; $ x = $ index_no - $ y * 10;' – Sikian
你是對的,我跑了一次速度測試,看起來好像快了9%。 (至少在我的服務器上使用PHP 5.3.3) 我會編輯我的答案。 –
似乎在第一種情況下得到$ x不正確。如果index_no是13,$ y = 1和$ x = -37 – Miuranga