1
我想創建一個簡單的動態畫廊與每個圖像下的單選按鈕,以允許用戶選擇圖像並提交表單。我不關心處理表單,我只想弄清楚如何動態生成表單。目前我正在用這個創建畫廊;圖像與單選按鈕(無數據庫)在php
<?php
$images = "image_gallery/";
$big = "big/";
$cols = 2;
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo '<table width="100%" cellspacing="3"><tr>';
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo '</tr><tr><td colspan="2"><hr /></td></tr><tr>';
echo '<td align="center"><a href="' . $images . $big . $file . '"><img src="' . $images . $file . '" /></a></td>';
$colCtr++;
}
echo '</table>' . "\r\n";
?>
它好像我應該創建foreach循環內的單選按鈕,但我不知道究竟在何處,或如何。
我很感激任何幫助。