Show All Data From Database with the help of Simple Api & Ajax

 

<?php

$conmysqli_connect('localhost','root','','test');

$sql = "select * from student";


$result = mysqli_query($con,$sql);
$count = mysqli_num_rows($result);
//header("Content-Type:Apllication/json");
if($count>0){
    while($data = mysqli_fetch_assoc($result)){
        $arr[]=$data;
    }


    $arr = json_encode($arr,JSON_PRETTY_PRINT);
    print_r$arr );


}else{
    echo "Data Not Found";
}

 


Show All Data From Database with the help of Simple Api & Ajax




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<h1>Hello</h1>
<center><h1>All Student</h1></center>
<table width="100%" border="1" rule="all">
<thead>
<tr>
<th>Sr No</th>
<th>Name</th>
<th>Father Name</th>
<th>Mobile</th>
<th>DOB</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody id="data">
    

</tbody>
</table>


<script src="jquery.min.js"></script>
<script>
$('#document').ready(function(){

    $.ajax({

type:'GET',
success:function(result){
   
   //console.log(result);
   var data = JSON.parse(result);
   //console.log(data );
   data.forEach(myfunction);
   

   function myfunction(result)
   {

    if (data.length > 0) {

        var temp = "";
        data.forEach((itemData=> {
        temp += "<tr>";
        temp += "<td>" + itemData.id + "</td>";
        temp += "<td>" + itemData.name + "</td>";
        temp += "<td>" + itemData.fname + "</td>";
        temp += "<td>" + itemData.mobile + "</td>";
        temp += "<td>" + itemData.dob"</td>";
       
        });
        document.getElementById('data').innerHTML = temp;
    }

   }
}

});



});

</script>
</body>
</html>

 

Show All Data From Database with the help of Simple Api & Ajax