下拉菜单不起作用(不同的用户任务)

时间:2017-03-01 05:14:08

标签: javascript php html drop-down-menu dropdown

我制作了一个用户有不同任务的系统。我在第二个下拉菜单中遇到了问题。只有第一个下拉菜单功能。我通过循环分离查询但仍然无效。我该怎么做才能解决它?

$CurrentID = $_SESSION['username'];
$CurrentID = strtoupper($CurrentID);

$sql = "SELECT * FROM task WHERE user_id=?"
$params = array($CurrentID);
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$query = sqlsrv_query($conn, $sql, $params, $options);

<li>
    <a href="javascript:;" data-toggle="collapse" data-target="#sro"><i class="fa fa-circle-o-notch"></i> SRO <i class="fa fa-fw fa-caret-down"></i></a>
    <ul id="sro" class="collapse">   
        <?php
            while ($result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { //LOPPING FOR SRO
                //$url_id_f = $result[3]; //get url_id
                if ($result['url_id'] == '5') {
                    echo "<p><a href='add_sro.php'><i class='fa fa-plus-square-o' aria-hidden='true'></i> Add New SRO</a></p> ";
                }

                if ($result['url_id'] == '30') {
                    echo '<p><a href="edit_sro.php"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit Service Request Order</a></p> ';
                }

                if ($result['url_id'] == '48') {
                    echo '<p><a href="view_sro.php"><i class="fa fa-list" aria-hidden="true"></i> View/Delete SRO</a></p> ';
                }

                if ($result['url_id'] == '7') {
                    echo '<p><a href="approval_cbw.php"><i class="fa fa-check-circle" aria-hidden="true"></i> Approval by Client Business Owner</a></p> ';
                }

                if ($result['url_id'] == '8') {
                    echo '<p><a href="approval_his.php"><i class="fa fa-check-circle" aria-hidden="true"></i> Approval by HIS</a></p> ';
                }
            }
            ?>
    </ul>
</li>
<li>
    <a href="javascript:;" data-toggle="collapse" data-target="#billing"><i class="fa fa-circle-o-notch"></i> Billing <i class="fa fa-fw fa-caret-down"></i></a>
    <ul id="billing" class="collapse">
        <?php 
        while ($result2 = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { //LOPPING FOR ADMINISTRATION
            if ($result['url_id'] == '8') {
                echo '<p><a href="dis_quotation.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Quotation</a></p>';
            }

            if ($result2['url_id'] == '8') {
                echo '<p><a href="dis_loa.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload LOA</a></p>';
            }      

            if ($result2['url_id']== '13') {
                echo '<p><a href="dis_atb.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Advice To Bill</a></p> ';
            }

            if ($result2['url_id'] == '19') {
                echo '<p><a href="dis_invoice.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Invoice</a></p> ';
            }

            if ($result2['url_id'] == '22') {
                echo '<p><a href="dis_update_payment.php"><i class="fa fa-pencil" aria-hidden="true"></i> Update Payment</a></p> ';
            }

            if ($result2['url_id'] == '22') {
                echo '<p><a href="dis_loa.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload LOA</a></p>';
            }
        }
        ?>
    </ul>
</li>

1 个答案:

答案 0 :(得分:0)

一旦执行结果,您的sqlsrv_fetch_array将返回null。所以第二次你无法从中获取数据。

如果你想第二次循环,那么你必须再次执行查询或者你可以先在数组中存储数据,然后多次遍历数组

$CurrentID = $_SESSION['username'];
$CurrentID = strtoupper($CurrentID);

$sql = "SELECT * FROM task WHERE user_id=?"
$params = array($CurrentID);
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$query = sqlsrv_query($conn, $sql, $params, $options);

<li>
    <a href="javascript:;" data-toggle="collapse" data-target="#sro"><i class="fa fa-circle-o-notch"></i> SRO <i class="fa fa-fw fa-caret-down"></i></a>
    <ul id="sro" class="collapse">   
        <?php
            while ($result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { //LOPPING FOR SRO
                //$url_id_f = $result[3]; //get url_id
                if ($result['url_id'] == '5') {
                    echo "<p><a href='add_sro.php'><i class='fa fa-plus-square-o' aria-hidden='true'></i> Add New SRO</a></p> ";
                }

                if ($result['url_id'] == '30') {
                    echo '<p><a href="edit_sro.php"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit Service Request Order</a></p> ';
                }

                if ($result['url_id'] == '48') {
                    echo '<p><a href="view_sro.php"><i class="fa fa-list" aria-hidden="true"></i> View/Delete SRO</a></p> ';
                }

                if ($result['url_id'] == '7') {
                    echo '<p><a href="approval_cbw.php"><i class="fa fa-check-circle" aria-hidden="true"></i> Approval by Client Business Owner</a></p> ';
                }

                if ($result['url_id'] == '8') {
                    echo '<p><a href="approval_his.php"><i class="fa fa-check-circle" aria-hidden="true"></i> Approval by HIS</a></p> ';
                }
            }
            ?>
    </ul>
</li>
<li>
    <a href="javascript:;" data-toggle="collapse" data-target="#billing"><i class="fa fa-circle-o-notch"></i> Billing <i class="fa fa-fw fa-caret-down"></i></a>
    <ul id="billing" class="collapse">
        <?php 
        $query = sqlsrv_query($conn, $sql, $params, $options); // execute query again
        while ($result2 = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { //LOPPING FOR ADMINISTRATION
            if ($result['url_id'] == '8') {
                echo '<p><a href="dis_quotation.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Quotation</a></p>';
            }

            if ($result2['url_id'] == '8') {
                echo '<p><a href="dis_loa.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload LOA</a></p>';
            }      

            if ($result2['url_id']== '13') {
                echo '<p><a href="dis_atb.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Advice To Bill</a></p> ';
            }

            if ($result2['url_id'] == '19') {
                echo '<p><a href="dis_invoice.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload Invoice</a></p> ';
            }

            if ($result2['url_id'] == '22') {
                echo '<p><a href="dis_update_payment.php"><i class="fa fa-pencil" aria-hidden="true"></i> Update Payment</a></p> ';
            }

            if ($result2['url_id'] == '22') {
                echo '<p><a href="dis_loa.php"><i class="fa fa-upload" aria-hidden="true"></i> Upload LOA</a></p>';
            }
        }
        ?>
    </ul>
</li>