开发者

images with radio buttons (no database) in php

I'm trying to create a simple dynamic gallery with a radio button under each image to allow the user to select an image and submit the form. I'm not concerned with processing the form yet, I'd just like to figure out how to dynamically generate the form. Currently I'm creating the gallery with this;

  <?php 

$images = "image_gallery/"; 
$big    =开发者_C百科 "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"; 

?>

It seems as though I should create the radio buttons inside of the foreach loop, but I'm not sure exactly where, or how.

I appreciate any help.


in your foreach loop:

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"; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜