Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.22 KB | None | 0 0
  1. //index.html
  2.  
  3. <html>
  4. <head>
  5.     <script src="jquery.min.js"></script>
  6. </head>
  7. <body>
  8.     <button onclick="getData()">Click me</button>
  9.     <div id="result">
  10.        
  11.     </div>
  12. </body>
  13. <script>
  14.     function getData(){
  15.         $.ajax({
  16.             url: "proccess.php",
  17.             type: "POST",
  18.             success: function(data){//laman ng data ay yung table
  19.                 var result = data;
  20.                 var parsedData = JSON.parse(result);//convert to ojbect ulit
  21.                
  22.                 for(var i = 0;i < parsedData.length; i++){
  23.                     $("#result").append("<p> ID:" + parsedData[i].id + ", Name:" + parsedData[i].username + ", password:" +parsedData[i].password + "</p>")
  24.                 }
  25.             }, error: function(xhr){
  26.            
  27.             }
  28.         });
  29.     }  
  30. </script>
  31. </html>
  32.  
  33. //proccess.html
  34.  
  35. <?php
  36. include("dbconn.php");
  37.  
  38. $query = mysql_query("SELECT * FROM user");//
  39.  
  40. if(mysql_num_rows($query) > 0){ //para macheck nya kung may laman
  41.     $array = array();//d2 issave ung laman ng table
  42.     while($row=mysql_fetch_array($query)){
  43.         $obj = new stdClass();// create object
  44.         $obj->id = $row['id']; //create object name with data row
  45.         $obj->username = $row['username'];
  46.         $obj->password = $row['password'];
  47.        
  48.         array_push($array, $obj);//insert all $obj to $arr
  49.     }
  50.    
  51.     echo json_encode($array); // convert to string
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement