制御構造ループ 5−3
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja"><head>
<meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="./style.css">
<title>ループで作るギャラリー</title></head>
<body><div class="file2">
<span style="font-size=30px;font-family:arial black;color:#0000FF;padding:30px">
-- Gallery --</span><br><br>
<form action="05_03_loop.php" method="post">
<input type="text" name="data" size="3">
<input type="submit" value="変更"> 横に何枚並べるか、指定してください。</form>
<?php
error_reporting(1);
$data = $_POST['data'];
$data = htmlspecialchars($data, ENT_QUOTES); /*タグを無効化 */
if($data == 0){
} else {
$width =600/$data; /*(600-($data-1)*3)/$data; */
$height = $width/4*3;
echo "<table border ='0'><tr>¥n";
for($a = 0; $a < 18;$a++) {
echo "<td><a href='pict/pict".$a.".jpg' target='_blank'>";
echo "<img src = 'pict/pict".$a.".jpg' width = $width height= $height border='0'>";
echo "</a></td>¥n";
if($a == 17){
echo "</tr></table>";
} else if($a%$data == $data-1){
echo "</tr>¥n<tr>¥n";
}
}
}
?> </div></body></html>