Test Case
- Read all Students and their city names using PHP and MySQL and convert into JSON
- Show all the student names and their city names on the webpage using AngujarJS
- When we type name of a student or city name filter the records
PHP & MySQL code
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<input type="text" ng-model="name">
<ul>
<span ng-repeat="x in names | filter:name">
<div>
Name {{ x.name}}
City {{x.city}}
</div>
</span>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
<?php
$cn=mysqli_connect("localhost","root","","cbp");
$sql="Select name,city from student";
$result=mysqli_query($cn,$sql);
while($r=mysqli_fetch_row($result))
{
?>
{name:'<?php echo $r[0]?>',city:'<?php echo $r[1]?>'},
<?php
}
mysqli_close($cn);
?>
];
});
</script>
</body>
</html>
Front-End using HTML, AngularJS and JSON
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<input type="text" ng-model="name">
<p>Looping with objects:</p>
<ul>
<span ng-repeat="x in names | filter:name">
<div>
Name {{ x.name}}
City {{x.city}}
</div>
</span>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
{name:'Rakesh Kumar',city:'Ghaziabad'},
{name:'Nitin Verma',city:'Delhi'},
{name:'Jatin Kumar',city:'Delhi'},
{name:'Vivek Verma',city:'Ghaziabad'},
];
});
</script>
</body>
</html>
Assignment
Create a table Item having fields
1. Itemcode,char,10, primary key
2. Itemname, varchar, 50, not null
3. Price, float, not null
4. Description, varchar, 250, not null
5. Image, varchar, 15, not null (Use the ItemCode as File Name with given extension from .jpg, .gif,.png)
Create a form input the data and save input database
Show all the items on the web page with filter
- Read all Students and their city names using PHP and MySQL and convert into JSON
- Show all the student names and their city names on the webpage using AngujarJS
- When we type name of a student or city name filter the records
PHP & MySQL code
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<input type="text" ng-model="name">
<ul>
<span ng-repeat="x in names | filter:name">
<div>
Name {{ x.name}}
City {{x.city}}
</div>
</span>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
<?php
$cn=mysqli_connect("localhost","root","","cbp");
$sql="Select name,city from student";
$result=mysqli_query($cn,$sql);
while($r=mysqli_fetch_row($result))
{
?>
{name:'<?php echo $r[0]?>',city:'<?php echo $r[1]?>'},
<?php
}
mysqli_close($cn);
?>
];
});
</script>
</body>
</html>
Front-End using HTML, AngularJS and JSON
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<input type="text" ng-model="name">
<p>Looping with objects:</p>
<ul>
<span ng-repeat="x in names | filter:name">
<div>
Name {{ x.name}}
City {{x.city}}
</div>
</span>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
{name:'Rakesh Kumar',city:'Ghaziabad'},
{name:'Nitin Verma',city:'Delhi'},
{name:'Jatin Kumar',city:'Delhi'},
{name:'Vivek Verma',city:'Ghaziabad'},
];
});
</script>
</body>
</html>
Assignment
Create a table Item having fields
1. Itemcode,char,10, primary key
2. Itemname, varchar, 50, not null
3. Price, float, not null
4. Description, varchar, 250, not null
5. Image, varchar, 15, not null (Use the ItemCode as File Name with given extension from .jpg, .gif,.png)
Create a form input the data and save input database
Show all the items on the web page with filter
No comments:
Post a Comment