【问题标题】:images with radio buttons (no database) in phpphp中带有单选按钮(无数据库)的图像
【发布时间】:2011-09-03 20:01:11
【问题描述】:

我正在尝试创建一个简单的动态图库,每个图像下都有一个单选按钮,以允许用户选择图像并提交表单。我还不关心处理表单,我只想弄清楚如何动态生成表单。目前我正在用这个创建画廊;

  <?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 循环内创建单选按钮,但我不确定确切的位置或方式。

感谢您的帮助。

【问题讨论】:

    标签: php forms radio-button


    【解决方案1】:

    在你的 foreach 循环中:

    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><input type="radio" name="should be common if to choose one between mutiples" value="the value you want to send via form" /></td>';
      $colCtr++; 
    } 
    
    echo '</table>' . "\r\n"; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 2013-03-22
      • 1970-01-01
      • 2016-08-26
      相关资源
      最近更新 更多