Saturday, 4 December 2021

PHP#4 post_bt2.php | post_bt2_xuly.php //Tạo form cho phép người dùng nhập vào số dòng, số cột và nút thực hiện. Khi người dùng click nút thực hiện, dữ liệu trên form sẽ truyền qua file xử lý và hiển thị 1 bảng có số dòng, số cột tương ứng.

//post_bt2.php

<!doctype html>

<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
/*
Tạo form cho phép người dùng nhập vào số dòng, số cột và nút thực hiện. Khi người dùng click nút thực hiện, dữ liệu trên form sẽ truyền qua file xử lý và hiển thị 1 bảng có số dòng, số cột tương ứng.
*/


?>
<form id="form1" name="form1" method="post" action="post_bt2_xuly.php">
<p>
<label for="dong">Số dòng:</label>
<input type="text" name="dong" id="dong">
</p>
<p>
<label for="cot">Số cột:</label>
<input type="text" name="cot" id="cot">
</p>
<p>
<input type="submit" name="taobang" id="taobang" value="Tạo bảng">
</p>
</form>
</body>
</html>

//post_bt2_xuly.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST['dong'],$_POST['cot']))
{
$d=$_POST['dong'];
$c=$_POST['cot'];
?>
<table width="80%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<?php
for($i=1;$i<=$d;$i++)
{
?>
<tr>
<?php
for($j=1;$j<=$c;$j++)
{
?>
<td>&nbsp;</td>
<?php } // kết thúc for j ?>
</tr>
<?php } //kết thúc for i ?>
</tbody>
</table>
<?php } ?>
</body>
</html>

0 comments:

Post a Comment