我正在做一个允许用户选择要创建的课程的程序。但是,我不知道如何为这个动态文本框实现for循环。 这是我的第一个文件
<!DOCTYPE html>
<html>
<body>
<form action="k1levelselect.php" method="post">
How many lessons do you want to create? <input type="text" name="number" value=""><br>
<input type="submit" value="Submit">
</form>
<p>Type the number of lessons you want to create and click 'Submit'.</p>
</body>
</html>
这是我的k1levelselect.php,用户输入一个数字后点击提交。
<html>
<head>
<title>Level Buttons</title>
<link rel="stylesheet" type="text/css" href="button.css" />
<center>
</head>
<body>
<br><img src ="http://i1370.photobucket.com/albums/ag263/Darlene_Fong/makeselection_zps10361dab.jpg"/></br>
<body background="sky.jpg"></body>
<br>
<?php
$noOfLesson = $_POST['number'];
for($noOfLesson=1;$noOfLesson<=10;){
echo "<td>";
echo 'k1level1.php' ;
echo "</div></td>";
}
?>
<div>
<a href="k1level1.php"><span>Lesson 1</span></a>
</div>
<br>
<div>
<a href="k1level2.php"><span>Lesson 2</span></a>
</div>
<br>
<div>
<a href="k1level3.php"><span>Lesson 3</span></a>
</div>
<br>
<div>
<a href="k1level4.php"><span>Lesson 4</span></a>
</div>
<br>
<div>
<a href="k1level5.php"><span>Lesson 5</span></a>
</div>
<br>
<div>
<a href="k1level6.php"><span>Lesson 6</span></a>
</div>
<br>
<div>
<a href="k1level7.php"><span>Lesson 7</span></a>
</div>
<br>
<div>
<a href="k1level8.php"><span>Lesson 8</span></a>
</div>
<br>
<div>
<a href="k1level9.php"><span>Lesson 9</span></a>
</div>
<br>
<div>
<a href="k1level10.php"><span>Lesson 10</span></a>
</div>
<br>
<a href="kindergardenselect.php"><b>Back</b></a>
</center>
</body>
</html>
如何编辑for循环,以便当用户输入7时,只会出现最多7个级别?
答案 0 :(得分:1)
for ($i=1; $i < $noOfLesson ; $i++) {
echo "<div>";
echo "<a href='k1level$i.php'>Lesson $i</a>" ;
echo "</div>";
}
循环学习每一课并设置&#34;等级&#34;用你的计数器变量。
答案 1 :(得分:0)
像这样修复你的for循环
for($noOfLesson = 1; $noOfLesson < 10; $noOfLesson++) {
echo "<td>";
echo 'k1level'.$noOfLesson.'.php' ;
echo "</div></td>";
}