<div id="acc" class="container-fluid" class="col-lg-10 col-md-12 col-sm-12 col-xs-12">

    <div class="card">
        <div id="form_headar" class="header">
            <h2 id="ex_head"> Outstanding Amount
            </h2>
        </div>
        <br />
        <div id="form_out_amount" class="header">
            <h1 id="out_amount" style="color:red;">
                USD <?php
                    $user_type_id = $_SESSION['user_type_id'];
                    $user_id = $_SESSION['user_id'];

                    if ($user_type_id == 1) {

                        $sql_6 = "SELECT * FROM excursions WHERE val='1'";
                    } else {
                        $sql_6 = "SELECT * FROM excursions WHERE val='1' AND promote_guide_id='" . $user_id . "'";
                    }
                    $y = 0;
                    $result_6 = mysqli_query($db, $sql_6);

                    while ($row_6 = mysqli_fetch_array($result_6)) {
                        $y = $y + $row_6['rate'];
                    }



                    if ($user_type_id == 1) {
                        $sql_5 = "SELECT * FROM payments WHERE val='1'";
                    } else {
                        $sql_5 = "SELECT * FROM payments WHERE val='1' AND promote_guide_id='" . $user_id . "'";
                    }
                    $result_5 = mysqli_query($db, $sql_5);
                    $x = 0;
                    while ($row_5 = mysqli_fetch_array($result_5)) {
                        $x = $x + $row_5['amount'];
                    }



                    echo    $y - $x;

                    ?>
            </h1>
        </div>


    </div>

</div>