PHP多个后续HTML选择字段

I want to create a form with multiple follow-up select fields. This from an array that contains 3 fields: ID, Name, followingID. FollowingID's matches an ID so we can figure out the layers.

Small scale example: 0 = ID, 1 = Name, 2 = followingID

    Array
       (
        [0] => Array
            (
                [0] => 1
                [1] => Auto’s, werktuigkundigen, technici, ingenieurs
                [2] => 0
            )

        [1] => Array
            (
                [0] => 2
                [1] => Bewaking, leger, politie
                [2] => 1
            )

        [2] => Array
            (
                [0] => 3
                [1] => Bouw, montage
                [2] => 1
            )

        [3] => Array
            (
                [0] => 4
                [1] => Commercieel, winkel, inkoop en verkoop
                [2] => 2
            )

        [4] => Array
            (
                [0] => 5
                [1] => Financiën, bank, verzekering
                [2] => 2
            )

        [5] => Array
            (
                [0] => 6
                [1] => Gezondheidszorg, paramedici, laboratorium
                [2] => 3
            )

        [6] => Array
            (
                [0] => 7
                [1] => Gezondheidszorg, paramedici, laboratorium
                [2] => 4
            )

In this case level 1 -> followingID = 0

Level 2 -> followingID = 1 if chosen first option

I can not figure out a way to do this without putting everything manually in a jquery script.

I figured something out. It's not pretty but it works. Does anyone know a better solution?

<script>
    $(document).ready(function() {
        var followingID = 0;
        $(".jobs").hide();
        $("#0").show();

        $(".jobs").change(function() {
            var id = $(this).attr("id");
            var ref = $(this).attr("value");
            $(".jobs").hide();
            $(".jobs").removeAttr("name");
            $("#0").show();
            $("#" + id).show();
            $("#" + this.value).show();
            $('option[ref="' + id + '"]').parent().show();
            if ($("#" + this.value).length == 0) {
                $("#" + id).attr("name", "sdata[]");
            }
        });

    });
</script>

<?
    function renderAllJobs() {
        $jobs = getJobs();
        $followingID = -1;
        $html = '';
        foreach ($jobs as $job) {
            if ($followingID != $job[2]) {
                if ($followingID > -1) {
                    $html .= '</select></p>';
                }
                $followingID = $job[2];
                $html .= '<p><select class="jobs" ref="' . $job[2] . '" id="' . $followingID . '">
            <option value="0">Maak een keuze</option>';
            }
            $html .= '<option ref="' . $job[0] . '" value="' . $job[0] . '">' . $job[1] . '</option>';

        }
        $html .= '</select></p>';
        return $html;

    }

    echo renderAllJobs();