php - 动态列表框 - 我的知识有很多空白
问题描述
我想要实现的是构建一组 3 个列表框。这个想法是允许用户从模糊(主要)向下钻取到详细(第三级)。为此,我的意图是让次要列表包括在主要列表中选择的内容,依此类推。
所以在顶层我有这个;
<html>
<body>
<h1>Please use this page to enter the project details of the work completed</h1>
<Form action ="get_primary.php" method = "post">
Primary: <input type = "text" name ="ws_desc_primary" value = "$primary" /> <br><br>
<input type="submit" value="click" name="submit" />
</Form>
<Form action ="get_secondary.php" method = "post">
Secondary: <input type = "text" name ="ws_desc_secondary" value = "$secondary" /> <br><br>
<input type="submit" value="click" name="submit" />
</Form>
<Form action ="get_tertiary.php" method = "post">
Tertiary: <input type = "text" name ="ws_desc_tertiary" value = "$tertiary" /> <br><br>
<input type="submit" value="click" name="submit" />
</Form>
</body>
</html>
我想要的是例如 name ="ws_desc_primary" 来显示 get_primary.php 的结果。一旦用户从该列表中选择了“$secondary”,就会使用 get_secondary.php 的结果填充。
你可以在下面看到这些 php 文件。有一个 get_tertiary 但我希望有足够的指导我可以自己添加那个。
我很确定这里需要javascript来处理动态的东西,但我真的很挣扎。
任何帮助是极大的赞赏。
谢谢
get_primary.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "worksheets";
$customer = "Manchester";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = 'call worksheets.get_primary("'.$customer.'" )';
$descriptions = array();
if ($result = mysqli_query($conn, $sql)) {
foreach($result as $value){
$descriptions = $value;
}
} else {
echo "Error getting description: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
get_secondary.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "worksheets";
$customer = "Manchester";
$primary = $_POST['ws_desc_primary'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = 'call worksheets.get_secondary("'.$customer.'" ,"'.$primary.'")';
$descriptions = array();
if ($result = mysqli_query($conn, $sql)) {
foreach($result as $value){
$descriptions = $value;
}
} else {
echo "Error getting description: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
解决方案
推荐阅读
- java - 如何在java中将属性从一个对象复制到另一个对象
- python - XML 用具有多个键值的相同标签来 dict Python
- visual-studio - 如何使用配置命令行执行 SSIS 包
- arduino-uno - LCD显示奇怪的神秘字符
- python - eth-brownie 'Accounts' 对象没有属性 'connect_to_clef'
- javascript - 我在添加新对象来存储 React redux 时遇到问题
- python - mmdevice 音频输出错误:无法初始化 COM(错误 0x80010106)
- php - 将当前用户发送到 laravel 中的工作
- ios - Flutter:当用户没有注册卡时如何添加设置Apple Pay按钮功能
- git - Git 没有将我的一个项目推送到 Github