Displaying records taken from MySQL database

Angular PHP MySQL data listing
By using Angular JS we will receive data from our MySQL sample table by using JSON format and then display the rows.
The Angular JS code is here.
<div ng-app="my_app" ng-controller="studentCtrl">

  <tr ng-repeat="x in details">
    <td>{{ x.name }}</td><td>{{ x.class }}</td><td>{{ x.mark }}</td>


var app = angular.module('my_app', []);
app.controller('studentCtrl', function($scope, $http) {
  .then(function (response) {$scope.details = response.data.student_data;});
Here is the output
{{ x.name }}{{ x.class }} {{ x.mark }}

Back end PHP code

Usually we have two common ways of connecting to MySQL database.

Using PDO
Using MySQLi
Here is the code using MySQLi
Here the variable $connection is declared inside the database connection file config.php. Read more on MySQL database connection file config.php here.
require "config.php"; // mysqli connection string 

$result = $connection->query("SELECT id,name,class,mark FROM student LIMIT 0,10");
$row = array();
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
$row[] = $rs;

echo json_encode(array("student_data"=>$row));

Using PDO

The variable $dbo is declared inside the database connection file config.php, read more on PDO connection and config file here.
require "config.php"; // database connection 

$sql="SELECT id, name ,class ,mark FROM student LIMIT 0,10"; 

echo json_encode($result); 

Populating data from MySQL table as options of drop down select box.
Angular Home

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
©2000-2023 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer