【发布时间】:2021-07-27 07:58:42
【问题描述】:
我正在尝试编写代码来扩展和收缩 PHP 中乘法表中的行和列。这是我目前拥有的代码,我认为可以扩展和收缩行和列:
<?php
$row=4;
$col=4;
if(isset($_GET["row"]))
{
$row=$_GET["row"];
}
if(isset($_GET["col"]))
{
$col=$_GET["col"];
}
?>
<html style="background-color: #90A7E8;">
<meta name="viewport" content="width=device-width, initial-scale=1">
<html lang="en">
<head>
<body>
<ul>
<?php
echo "<table>";
for($r=1;$r<$row+1;$r++){
echo "<tr>";
for($c=1;$c<$col+1;$c++){
$p=$c*$r;
//~ echo "<td>";
echo "<td>$p</td>";
//~ echo "</td>";
}
echo "</tr>";
}
echo "</table><br>";
$row++;
echo "</ul><a href='math.php?row=$row?col=$col'>more rows</a><br>";
$row-=1;
echo "<a href='math.php?row=$row?col=$col'>less rows</a><br>";
$col++;
echo "<a href='math.php?row=$row?col=$col'>more columns</a><br>";
$col-=1;
echo "<a href='math.php?row=$row?col=$col'>less columns</a><br>";
?>
</body>
</html>
当我运行代码时,我不断收到此错误以及无法扩展和收缩列。我在这行代码中得到一个格式不正确的数值错误:for($r=1;$r<$row+1;$r++)
当我尝试扩展和收缩列时,它只会收缩行。
总而言之,我有一个乘法表,我想仅使用 PHP 来扩展和收缩行和列。当我运行上面指定的代码时,我在上面指定的行上收到一条错误消息“遇到格式不正确的数值”,并且无法扩展或收缩列。有谁能帮帮我吗?
【问题讨论】:
标签: php html html-table