<?php
    /*===
        function: build_dept_drop_down: void -> void
        purpose: expects nothing,
            tries to build and output a dynamically-built
                select/drop-down element containing the current
                department names and numbers,
            and returns nothing.
            *   if it cannot connect to the database,
                hum_conn_sess should cause it to complain and then exit,
                including destroying the current session and including a
                link to hopefully-conveniently start over

        requires: hum_conn_sess.php

        last modified: 2024-04-17
    ===*/

    function build_dept_drop_down()
    {
        // try to query department names and numbers

        $conn = hum_conn_sess();

        $dept_stmt = oci_parse($conn, "select dept_num, dept_name
                                       from dept
                                       order by dept_name");

        oci_execute($dept_stmt, OCI_DEFAULT);

        // they chose select/drop-down box!

        ?>
                <select name="dept">
        <?php

        while (oci_fetch($dept_stmt))
        {
            $next_dept_num = oci_result($dept_stmt, "DEPT_NUM");
            $next_dept_name = oci_result($dept_stmt, "DEPT_NAME");

            ?>
                    <option value="<?= $next_dept_num ?>">
                        <?= $next_dept_name ?> </option>
           <?php
        }

        ?>
                </select>
        <?php

        oci_free_statement($dept_stmt);
        oci_close($conn);
    }
?>