EnSabahNur Posted January 6, 2015 Share Posted January 6, 2015 I am trying to get data out off a mysql database, by using an php file. But i am not getting any output? Examples.html <html ng-app="countryApp"> <head> <meta charset="utf-8"> <title>Angular.js Example</title> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> <script> var countryApp = angular.module('countryApp', []); countryApp.controller('CountryCtrl', function ($scope, $http){ $http.get('category.php').success(function(data) { $scope.countries = data; }); }); </script> </head> <body ng-controller="CountryCtrl"> <table> <tr ng-repeat="country in countries"> <td>{{country}}</td> </tr> </table> </body> </html> category.php <?php $servername = "localhost:3306"; $username = "root"; $password = "root"; $dbname = "myDB"; $conn = mysqli_connect($servername, $username, $password, $dbname); if(!$conn){ die("Connection failed: " .mysqli_connecet_error()); } $showData = "SELECT id FROM myDB"; $data = array(); $result = mysqli_query($conn, $showData); if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_assoc($result)){ $data[] = $row; } } else { echo "0 results"; }; print json_encode($data); mysqli_close($conn); echo($outp); ?> Link to comment https://forums.phpfreaks.com/topic/293702-angularjs-php-mysql-connection/ Share on other sites More sharing options...
mikosiko Posted January 6, 2015 Share Posted January 6, 2015 Obvious queations: - are you sure that your sql query is executing correctly - it is producing any results? - what is the contain of $data after the loop? - what is the contain after json_encode? And last but not least - where are you defining $outp? Link to comment https://forums.phpfreaks.com/topic/293702-angularjs-php-mysql-connection/#findComment-1501896 Share on other sites More sharing options...
CroNiX Posted January 6, 2015 Share Posted January 6, 2015 Are you sure the request is reaching your category.php script? If not, try using a full URL here: $http.get('category.php') Link to comment https://forums.phpfreaks.com/topic/293702-angularjs-php-mysql-connection/#findComment-1501916 Share on other sites More sharing options...
mac_gyver Posted January 7, 2015 Share Posted January 7, 2015 also, for the mysqli database library, the port number is a separate parameter, not part of the host parameter. Link to comment https://forums.phpfreaks.com/topic/293702-angularjs-php-mysql-connection/#findComment-1501982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.