首页 > 解决方案 > 动态列表框 - 我的知识有很多空白

问题描述

我想要实现的是构建一组 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);
?>

标签: phphtml

解决方案


推荐阅读