我有两种形式......
HTML
<html>
<head>
<title>Char Display</title>
</head>
<body>
<form method="post" action="seven.php">
ROWS <input type="text" name="rows"> COLUMNS <input type="text" name="cols"><input type="submit" value="Generate">
</form>
</body>
</html>
seven.php
<?php
if(isset($_POST['rows'])){
$rows=$_POST['rows'];
$cols=$_POST['cols'];
echo '<table border="1">';
for($row=1;$row<=$rows;$row++){
echo '<tr>';
for($col=1;$col<=$cols;$col++){
echo '<td></td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
该程序有两个文本字段,即行和列。 php脚本根据用户在行和列中的输入创建一个表。
我的问题是,如果程序有三个文本字段,即行,列和字母(从AZ输入一个字母),我不知道该怎么做,它会创建一个字母表(由user)基于用户也输入的行数和列数。请帮助!!
答案 0 :(得分:1)
如果还有其他输入
<html>
<head>
<title>Char Display</title>
</head>
<body>
<form method="post" action="seven.php">
ROWS <input type="text" name="rows">
COLUMNS <input type="text" name="cols">
DATA <input type="text" name="data">
<input type="submit" value="Generate">
</form>
</body>
</html>
在PHP代码中,读取数据字段并使用
分解数据中的字符 $data_char=explode('',$data);
现在回显$data_char
标记中展开的td
数组中的每个字母。
使用
$row*$col
)中具有值
isset($data_char[$row*$col])
<?php
if(isset($_POST['rows'])){
$rows=$_POST['rows'];
$cols=$_POST['cols'];
$data=$_POST['data'];
$data_char=explode('',$data); // Array of characters in the data
echo '<table border="1">';
for($row=1;$row<=$rows;$row++){
echo '<tr>';
for($col=1;$col<=$cols;$col++){
echo '<td>'.isset($data_char[$row*$col])?$data_char[$row*$col]:''.'</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>