Skip to content

Instantly share code, notes, and snippets.

@michaeldeboeve
Last active June 22, 2017 12:04
Show Gist options
  • Save michaeldeboeve/022b3e2097d7f2116356354d3917b5ed to your computer and use it in GitHub Desktop.
Save michaeldeboeve/022b3e2097d7f2116356354d3917b5ed to your computer and use it in GitHub Desktop.
Load .php file in angular
$http.get('/path/to/ami.php')
.then(function(response){
$scope.myResult = response.data;
});
<?php
// Connect to the Database
include 'db_connect.php';
// Query from Database
include 'db_main_query.php';
mysqli_close($conn);
?>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "myDB";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if(!$conn){
die("Connection failed: " .mysqli_connecet_error());
}
?>
<?php
$query = "SELECT * FROM table";
$data = array();
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
} else {
echo "0 results";
};
print json_encode($data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment