Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Angular Tutorial</title>
  6. <style>
  7. table, th , td {
  8. border: 1px solid grey;
  9. border-collapse: collapse;
  10. padding: 5px;
  11. }
  12. table tr:nth-child(odd) {
  13. background-color: #f1f1f1;
  14. }
  15. table tr:nth-child(even) {
  16. background-color: #ffffff;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21.  
  22. <div ng-app="myApp" ng-controller="customersCtrl">
  23.  
  24. <table>
  25. <tr ng-repeat="x in names">
  26. <td>{{ x.Name }}</td>
  27. <td>{{ x.Country }}</td>
  28. </tr>
  29. </table>
  30.  
  31. </div>
  32.  
  33. <table>
  34. <tr ng-repeat="x in names | orderBy : 'Country'">
  35. <td>{{ x.Name }}</td>
  36. <td>{{ x.Country }}</td>
  37. </tr>
  38. </table>
  39.  
  40. <table>
  41. <tr ng-repeat="x in names">
  42. <td>{{ x.Name }}</td>
  43. <td>{{ x.Country | uppercase }}</td>
  44. </tr>
  45. </table>
  46.  
  47. <table>
  48. <tr ng-repeat="x in names">
  49. <td>{{ $index + 1 }}</td>
  50. <td>{{ x.Name }}</td>
  51. <td>{{ x.Country }}</td>
  52. </tr>
  53. </table>
  54.  
  55. <table>
  56. <tr ng-repeat="x in names">
  57. <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Name }}</td>
  58. <td ng-if="$even">{{ x.Name }}</td>
  59. <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Country }}</td>
  60. <td ng-if="$even">{{ x.Country }}</td>
  61. </tr>
  62. </table>
  63.  
  64. <script>
  65. var app = angular.module('myApp', []);
  66. app.controller('customersCtrl', function($scope, $http) {
  67. $http.get("customers.php")
  68. .then(function (response) {$scope.names = response.data;});
  69. });
  70. </script>
  71.  
  72. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  73. <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js" type="text/javascript"></script>
  74. </body>
  75. </html>
  76.  
  77.  
  78.  
  79.  
  80. //////////// php part
  81.  
  82. <?php
  83.  
  84.  
  85. $method = $_SERVER['REQUEST_METHOD'];
  86.  
  87. $servername= "localhost";
  88. $username = "root";
  89. $password = "k";
  90. $dbname = "Assignment6";
  91.  
  92. // Create the connection
  93. $db = new mysqli($servername, $username, $password, $dbname);
  94.  
  95. // Check to make sure it worked
  96. if ($db->connect_error) {
  97. die("Connection failed: " . $db->connect_error);
  98. }
  99.  
  100. // Prepare and execute the SQL statement
  101. $sql = "SELECT Name, Country FROM customers";
  102. $result = $db->query($sql);
  103.  
  104. // Create an array to store the results in temporarily
  105. $resultArray = array();
  106.  
  107. // Put the resulting data into the
  108. while($row = $result->fetch_array(MYSQLI_ASSOC)) {
  109. $resultArray[] = $row;
  110. }
  111.  
  112. // Encode the array as JSON and send it back
  113. echo json_encode($resultArray);
  114.  
  115. // Close the connections
  116. $result->close();
  117. $db->close();
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement