我想作一個表單內含二維的表格
以下的程式法是我的作法
但我覺得這樣寫不是很漂亮
不知道有沒有更好的作法
(我本身是寫C & Java
php & html 是完全的新手
所以我的程式都還是以C & Java的概念去寫
有些觀念不對再麻煩各位指導一下
謝謝)
<!DOCTYPE html>
<html>
<body>
<?php
define("COLUMN", 3);
define("ROW", 4);
$cCount=1;
$rCount=1;
?>
<?php
function test($row_number) {
for($cCount = 1; $cCount <= COLUMN; $cCount++) {
?>
<td>
<?php if ($row_number == 1) {
echo $cCount;
} else {
?>
<input type="text" name="textfield<?php echo $cCount;?>"
/></td>
<?php
}
?>
</td>
<?php
}
}
?>
<!--create form-->
<form name="aform" action="test.php" method="post">
<!--create table-->
<table border="2">
<!--create the for loop-->
<?php for($rCount = 1; $rCount <= ROW; $rCount++){ ?>
<!--create 1 row for repeating-->
<tr>
<!--column 1 is to print out the counter for you to see.-->
<td><?php echo $rCount; ?></td>
<?php test($rCount); ?>
</tr>
<?php }?> <!--create the submit button -->
<tr>
<td>
<input type="submit" name="Submit" value="submit"/></td>
</tr>
</table>
</form>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.146.86.160
※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1405068896.A.73C.html
推
07/11 17:54, , 1F
07/11 17:54, 1F
→
07/11 17:54, , 2F
07/11 17:54, 2F
→
07/11 17:55, , 3F
07/11 17:55, 3F
→
07/11 18:40, , 4F
07/11 18:40, 4F
推
07/11 20:31, , 5F
07/11 20:31, 5F
→
07/11 21:16, , 6F
07/11 21:16, 6F
→
07/11 21:17, , 7F
07/11 21:17, 7F
→
07/11 21:24, , 8F
07/11 21:24, 8F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章