以下代码通过下拉列表显示数据,我想知道如何将其转换为用户在文本框中输入数字并单击设置时,根据他输入的数字显示动态下拉列表。
$query = mysqli_query($con, "SELECT * FROM topic WHERE SubCat = $subcat ");
echo "<select name='topdd' >";
echo " <option>--None Selected--</option>";
while ($row = mysqli_fetch_array($query)) {
echo "<option value='$row[topic_id]' selected>";
echo $row["title"];
echo "</option>";
}
echo "</select>";
答案 0 :(得分:0)
这段代码对你没问题?我做你的工作,下次尝试自己
<form method="POST">
<label for='choiceNumber'>Number of dropdowns choice</label>
<input type='number' name='choiceNumber'>
<input type='submit'>
</form>
<?php
$resultArray = array(1,2,3,4,5,6,7);
$display = "<select name='topdd'><option>--None Selected--</option>";
if (!empty($_POST['choiceNumber']) && $_POST['choiceNumber'] > 0) {
for($i = 0; $i < $_POST['choiceNumber']; $i++) {
$display .= "<option>".$resultArray[$i]."</option>";
}
}
echo $display."</select>";
?>