Advertisement
GWibisono

Untitled

Mar 23rd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['id']){
  3. $id=$_POST['id'];
  4. $nol=array(
  5. "nama"=>"Data Kosong",
  6. "alamat"=>"Data Kosong",
  7. "nomor"=>"Data Kosong",
  8. "ket"=>"Data Kosong"
  9. );
  10. $konek=mysqli_connect("localhost","root","","contoh");
  11. $lihat=mysqli_query($konek,"select * from nama");
  12. $numrows=mysqli_num_rows($lihat);
  13.  
  14. if($numrows==null){
  15. die( json_encode($nol) );
  16. }else{
  17.    $ar=array();
  18. while($row=mysqli_fetch_array($lihat))
  19.   $ar[]=$row;
  20. }
  21. echo json_encode($ar);die();
  22. }
  23. ?>
  24.  <html>
  25. <head>
  26. <meta charset="UTF-8">
  27. <script src="jquery.js"></script>
  28. <script>
  29. $(document).ready(function(){
  30. $('‪#‎id‬').click(function(){
  31. var isi=$('#id').val();
  32. $.ajax({
  33. url:"?d=data.php",
  34. type:"post",
  35. data:{id:isi},
  36. dataType:"json",
  37. beforesend:function(){
  38. $('‪#‎t‬').show();
  39. },
  40. success:function(data){
  41. var html='';
  42. $.each(data, function(i, item){
  43. html+='<p>'+data[i].nama+'</p>';
  44. html+='<p>'+data[i].alamat+'</p>';
  45. html+='<p>'+data[i].nomor+'</p>';
  46. html+='<p>'+data[i].ket+'</p>';
  47. )}
  48. $('‪#‎besar‬').append(html);
  49. $('#t').hide();
  50. }
  51. });
  52. });
  53. });
  54.  
  55. </script>
  56. </head>
  57. <body>
  58. <input type="submit" name="id" id="id" value='33' />
  59. <span id="t" style="display:none;"></span>
  60. <br>
  61. <div id="besar">
  62. <div id="nama"></div>
  63. <div id="alamat"></div>
  64. <div id="nomor"></div>
  65. <div id="ket"></div>
  66. </div>
  67.  
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement