explode

mail@pastecode.io avatar
unknown
php
3 years ago
4.7 kB
2
Indexable
Never
<?php
    
    include('config/config.php');
    function request_data($name){
        $fullname = explode(' ',$name);
        if(count($fullname) == 2){
            return $fullname;
        }else{
            return "Please, Enter First and Last Name";
        }
    }
    function get_person($conn,$name,$lname){
        $stmt = $conn->prepare("SELECT * FROM `piradoba` WHERE saxeli='$name' AND gvari='$lname'"); 
        $stmt->execute();

        // set the resulting array to associative
        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
        $list = array();
        foreach($stmt as $v) { 
            array_push($list, '<tr>'.'<td>'.$v['piradi nom'].'</td>'.
             '<td>'.$v['saxeli'].'</td>'.
             '<td>'.$v['gvari'].'</td>'.
             '<td>'.$v['quCa'].'</td>'.'</tr>');
            
            
        }
        return $list;
    }
if(isset($_POST['fullname'])){        
if(request_data($_POST['fullname'])==False){
        header('Location: index.php');
        exit() or die();
    }
}
?>

<?php
    include('header.php');
?>
    
    <div class="col-md-4">
        <form method="post" action="">
                <div class="form-group">
                    <label class="control-label">Full Name</label>
                    <div class="input-group">
                        <span class="input-group-addon">$</span>
                        <input class="form-control" type="text" name="fullname">
                        <span class="input-group-btn">
                            <input value="find" class="btn btn-default" type="submit" onclick="loading()">
                        </span>
                    </div>
                </div>
        </form>
    </div>
    
                           
                            <!--<div id="pageloader">-->

                            <!--<div class="progress progress-striped active">-->
                            <!--  <div id="loaderi" class="progress-bar progress-bar-info" style="width:20%">20%</div>-->
                            <!--</div>-->
                            
                            <!--</div>-->
    
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

    <style type="text/css">
        
        #pageloader{
            position: absolute;
            left: 0px;
            right: 0px;
            top: 0px;
            bottom: 0px;
            margin: auto;
            height: 25%;
            width: 50%;
            z-index:999;
        }

.progress-bar {
    background-color: #0f0 !important;
    color:black !important;
}

    </style>


<script type="text/javascript">
    $(document).ready(function(){
//  $("#pageloader").hide();
    $("button").click(function(){
    $("#pageloader").delay(0).fadeIn("fast");
    $("#pageloader").delay(3000).fadeOut("fast");

        });
});

</script>



<script>
function loading() {
  var elem = document.getElementById("loaderi");   
  var width = 20;
  var id = setInterval(frame, 30);
  function frame() {
    if (width >= 100) {
      clearInterval(id);
    } else {
      width++; 
      elem.style.width = width + '%'; 
      elem.innerHTML = width * 1  + '%';
    }
  }
}
</script>


    <div class="row">
            <div class="col-lg-12" style="overflow: auto;">
                <table class="table table-striped table-hover ">
                    <thead>
                        <?php
                        $name = request_data($_POST['fullname'])[0];
                        $last = request_data($_POST['fullname'])[1];
                        if(get_person($conn,$name,$last)==TRUE){
                            echo '
                        <tr>
                            <th>#ID</th>
                            <th>First Name</th>
                            <th>Last Name</th>
                            <th>Father</th>
                            
                        </tr>';
                        }
                        ?>
                    </thead>
                    <tbody>
                        
                        <?php 
                            $name = request_data($_POST['fullname'])[0];
                            $last = request_data($_POST['fullname'])[1];
                            foreach(get_person($conn,$name,$last) as $item){
                                echo $item;
                            }
                        ?>
                        
                    </tbody>
                </table> 
            </div>
    </div>


<?php
    include('footer.php');
?>