Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['id']){
- $id=$_POST['id'];
- $nol=array(
- "nama"=>"Data Kosong",
- "alamat"=>"Data Kosong",
- "nomor"=>"Data Kosong",
- "ket"=>"Data Kosong"
- );
- $konek=mysqli_connect("localhost","root","","contoh");
- $lihat=mysqli_query($konek,"select * from nama");
- $numrows=mysqli_num_rows($lihat);
- if($numrows==null){
- die( json_encode($nol) );
- }else{
- $ar=array();
- while($row=mysqli_fetch_array($lihat))
- $ar[]=$row;
- }
- echo json_encode($ar);die();
- }
- ?>
- <html>
- <head>
- <meta charset="UTF-8">
- <script src="jquery.js"></script>
- <script>
- $(document).ready(function(){
- $('#id').click(function(){
- var isi=$('#id').val();
- $.ajax({
- url:"?d=data.php",
- type:"post",
- data:{id:isi},
- dataType:"json",
- beforesend:function(){
- $('#t').show();
- },
- success:function(data){
- var html='';
- $.each(data, function(i, item){
- html+='<p>'+data[i].nama+'</p>';
- html+='<p>'+data[i].alamat+'</p>';
- html+='<p>'+data[i].nomor+'</p>';
- html+='<p>'+data[i].ket+'</p>';
- )}
- $('#besar').append(html);
- $('#t').hide();
- }
- });
- });
- });
- </script>
- </head>
- <body>
- <input type="submit" name="id" id="id" value='33' />
- <span id="t" style="display:none;"></span>
- <br>
- <div id="besar">
- <div id="nama"></div>
- <div id="alamat"></div>
- <div id="nomor"></div>
- <div id="ket"></div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement