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>
11
  • what error you are facing? Commented May 20, 2016 at 9:44
  • the html page is not showing data and remains the same Commented May 20, 2016 at 9:46
  • you print 2 json in php side. please remove 1 which is not correct. Commented May 20, 2016 at 9:47
  • phpMyAdmin is a tool written in PHP MYSQL is a DBMS Commented May 20, 2016 at 9:51
  • can u be more specific? Commented May 20, 2016 at 9:53

1 Answer 1

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)
       });
});
Sign up to request clarification or add additional context in comments.

6 Comments

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
did you remove that extra }); you added?
i have to leave the extra }): because without it the page isn't working
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
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)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.