0

im building a project with angular,i have a html form that sends data to "customers" table in MYSQL. now i want to show the data of "customers" table. this is my code that i tried to get that data but its not working. can anyone help?

php code:

<?php
  $con = mysqli_connect('localhost','root','','hamatkin');
  if(!$con){
    die("couldnt connect".mysqli_error);
  }
  $query = "SELECT * FROM customers";
  $result = $con->query($query);
  $r = array();
  if( $result->num_rows>0){
    while($row = $result->fetch_assoc()){
      $r[] = $row;
    }
  }
  $res = json_encode($r);
  echo $res;
  echo $sql_statement;
  ?>

controller:

"use strict";
var app = angular.module('dataSystem',[]);
app.controller('customerCardsCtrl',function($scope,$route,$location,$http){
    $http({method:'GET', url:'api/get-allCustomers.php'}).success(function(response){
        $scope.customers = response.data;
      });
    });
});

html code:

<!DOCTYPE html>
<html >
<head>
    <title></title>
</head>
<body>


    <div>
      <table ng-controller="customerCardsCtrl" >
        <tr ng-repeat="x in customers">
        <td> {{ x.customer_id}} </td>
        <td>{{ x.first_name }}</td>
        <td>{{ x.last_name }}</td>
        <td> {{ x.id}} </td>
        <td> {{ x.city}} </td>
        <td> {{ x.adress}} </td>
        <td> {{ x.phone}} </td>
        <td> {{ x.email}} </td>
        <td> {{ x.fax}} </td>
        <td> {{ x.referrer}} </td>
        <td> {{ x.comments}} </td>

        </tr>
        </table>
    </div>
</body>
</html>
Wasiq Muhammad
  • 2,770
  • 3
  • 14
  • 26

1 Answers1

0

use this code instead

"use strict";
var app = angular.module('dataSystem',[]);
app.controller('customerCardsCtrl',function($scope,$route,$location,$http){
  $http({method:'GET', url:'api/get-allCustomers.php'})
    .then(function(response){
           $scope.customers = response.data;
       }, function(response){
           console.log(response)
       });
});
  • the console showing me: warning tried to load angular more than once, and: script1002: syntax error customerCardsCtrl.js(8,1), and: error: [ng:areq] argument 'customerCardsCtrl' is not a function got undefined – Dennis Kapitankin May 20 '16 at 10:45
  • did you remove that extra }); you added? – Chukwuemeka Ihedoro May 20 '16 at 10:47
  • i have to leave the extra }): because without it the page isn't working – Dennis Kapitankin May 20 '16 at 10:54
  • the rest of your code is ok except that you must remove **echo $sql_statement;** in your php code. please try the edited controller code – Chukwuemeka Ihedoro May 20 '16 at 11:06
  • i removed echo_$sql statement, and i tried the edited code but the code makes the pages not to work , thats why i have to do an extra }); and then the page working great except not showing details from table "customers". but thanks for trying to help ! can u try to help in another program?(skype,teamviewer, chrome remote desktop) – Dennis Kapitankin May 20 '16 at 11:22
  • Yes, sure. Dennis can you please share your Skype details – Raju Dudhrejiya May 20 '16 at 11:42