<?php
session_start();
$UserID = $_SESSION['user_id'];
$userinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileusers WHERE user_id='$UserID'"));
    include 'load.php';
    require_once 'db_connection.php';  
    if(isset($_POST['route'])){
        $route = $_POST['route'];

       
        if($route==0){
            echo '<option value="0">Walk-in Customer</option>
                            <option value="dc">Delivery Customer</option>';

                            $cus2 = "SELECT * FROM mobilecustomers WHERE branch_id='".$userinfo['branch_id']."' AND status=1";
                                $result = $conn->query($cus2);
                                if ($result->num_rows > 0) {
                                    while ($row = $result->fetch_assoc()) {
                                        $coid = $row["coid"];
                                        $creditbalance = $row["ccredit"];
                                        $cname = $row["cname"];
                                        $cphone = $row["cphone"];
                                        echo '<option value="' . $coid . '">' . $cname . ' | ' . $cphone . ' | Rs.' . $creditbalance . '</option>';
                                    }
                                } 
        }else{
             $customerinfo = mysqli_query($conn, "SELECT * FROM mobilecustomers WHERE route='$route'");
                if ($customerinfo->num_rows > 0) {
                    
                    while($row = $customerinfo->fetch_assoc()) {
                        $coid = $row["coid"];
                                        $creditbalance = $row["ccredit"];
                                        $cname = $row["cname"];
                                        $cphone = $row["cphone"];
                                        echo '<option value="' . $coid . '">' . $cname . ' | ' . $cphone . ' | Rs.' . $creditbalance . '</option>';
                    }
                }

         }

    }
    
    
    
?>