카테고리 없음

php

boangod 2025. 9. 19. 17:27

 

배열을 생성하는 페이지 만들기.

 

table.html

 <html>
 <head>
 <title>입력 폼파일</title>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
 </head> 
<form method="post" action="table.php">
    행: <input type="text" name="row"><br>
    열 : <input type="text" name="col"><br>
        <input type="submit" name="확인" value="확인">
</form>
 </html>

 

 

table.php

<?
$row = $_POST["row"];
$col = $_POST["col"];
echo("행 : $row");
echo("<br>");
echo("열 : $col");
if ($row < 2 || $col < 2) {
    echo ("<script>
           window.alert('넌 나가라');
           history.go(-1);
           </script>");
           exit;
}

//배열 만들기
$ar = array();
$num = 1;
for($i=0; $i < $row; $i++){
    for($j=0; $j < $col; $j++){
        $ar[$i][$j] = $num++;
    }
}

// 테이블 만들기
echo("<table border = '1' style='border-collapse:collapse;'");
for($i=0; $i < $row; $i++){
    echo("<tr>");
    for($j=0; $j < $col; $j++){
        echo("<td width='84'>{$ar[$i][$j]}</td>");
    }
    echo("</tr>");
}
echo("</table>");


echo("<br><hr><br>");
show_source(__FILE__);
?>