Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Angular Tutorial</title>
- <style>
- table, th , td {
- border: 1px solid grey;
- border-collapse: collapse;
- padding: 5px;
- }
- table tr:nth-child(odd) {
- background-color: #f1f1f1;
- }
- table tr:nth-child(even) {
- background-color: #ffffff;
- }
- </style>
- </head>
- <body>
- <div ng-app="myApp" ng-controller="customersCtrl">
- <table>
- <tr ng-repeat="x in names">
- <td>{{ x.Name }}</td>
- <td>{{ x.Country }}</td>
- </tr>
- </table>
- </div>
- <table>
- <tr ng-repeat="x in names | orderBy : 'Country'">
- <td>{{ x.Name }}</td>
- <td>{{ x.Country }}</td>
- </tr>
- </table>
- <table>
- <tr ng-repeat="x in names">
- <td>{{ x.Name }}</td>
- <td>{{ x.Country | uppercase }}</td>
- </tr>
- </table>
- <table>
- <tr ng-repeat="x in names">
- <td>{{ $index + 1 }}</td>
- <td>{{ x.Name }}</td>
- <td>{{ x.Country }}</td>
- </tr>
- </table>
- <table>
- <tr ng-repeat="x in names">
- <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Name }}</td>
- <td ng-if="$even">{{ x.Name }}</td>
- <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Country }}</td>
- <td ng-if="$even">{{ x.Country }}</td>
- </tr>
- </table>
- <script>
- var app = angular.module('myApp', []);
- app.controller('customersCtrl', function($scope, $http) {
- $http.get("customers.php")
- .then(function (response) {$scope.names = response.data;});
- });
- </script>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
- <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js" type="text/javascript"></script>
- </body>
- </html>
- //////////// php part
- <?php
- $method = $_SERVER['REQUEST_METHOD'];
- $servername= "localhost";
- $username = "root";
- $password = "k";
- $dbname = "Assignment6";
- // Create the connection
- $db = new mysqli($servername, $username, $password, $dbname);
- // Check to make sure it worked
- if ($db->connect_error) {
- die("Connection failed: " . $db->connect_error);
- }
- // Prepare and execute the SQL statement
- $sql = "SELECT Name, Country FROM customers";
- $result = $db->query($sql);
- // Create an array to store the results in temporarily
- $resultArray = array();
- // Put the resulting data into the
- while($row = $result->fetch_array(MYSQLI_ASSOC)) {
- $resultArray[] = $row;
- }
- // Encode the array as JSON and send it back
- echo json_encode($resultArray);
- // Close the connections
- $result->close();
- $db->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement