title: Dynamic data for ng table
body: <p>This piece of code is working properly but I need to replace the data section with values from MySQL table using PHP:</p>
  
  <pre><code>function() {
  "use strict";
  angular.module("app.table").controller("nutritionController", ["$mdEditDialog", "$q", "$scope", "$timeout", function(e, t, a, o) {
      a.selected = [],
      a.limitOptions = [25, 50, 150, 300],
      a.options = {
          rowSelection: !1,
          multiSelect: !1,
          autoSelect: !1,
          decapitate: !1,
          largeEditDialog: !1,
          boundaryLinks: !1,
          limitSelect: !0,
          pageSelect: !1},
      a.query = {
          order: "stu",
          limit: 50,
          page: 1},
      a.desserts = {
           count: 2, 
           data: [{
              stu: "yada1", 
              mod: "yada1",
              cat: "yada1",
              com: "yada1",
              cru: "yada1",
              for: "yada1",
              con: "yada1",
              cmt: "yada1",
          }, {
              stu: "yada2", 
              mod: "yada2",
              cat: "yada2",
              com: "yada2",
              cru: "yada2",
              for: "yada2",
              con: "yada2",
              cmt: "yada2",
          }] 
          }
          }])
          }()
  </code></pre>
  
  <p>I would like to use PHP/MySQL to replace "data" section with data from a MySQL table. I tried this but it kept returning errors:</p>
  
  <pre><code>a.desserts = {
  count: 2,
  data: function($scope, $http) {
  $http.get("/URL/maindb.php")
  .then(function (response) {$scope = response.data.records})
  }
  </code></pre>
  
  <p>Here is the PHP file:</p>
  
  <pre><code>&lt;?php
  header("Access-Control-Allow-Origin: *");
  header("Content-Type: application/json; charset=UTF-8");
  
  $conn = new mysqli("localhost", "user", "password", "database");
  
  $result = $conn-&gt;query("SELECT stu, mod, cat, com, cru, for, con, cmt FROM maintable");
  
  $outp = "[";
  while($rs = $result-&gt;fetch_array(MYSQLI_ASSOC)) {
  if ($outp != "[") {$outp .= ",";}
  $outp .= '{"stu": "' . $rs["stu"]  . '",';
  $outp .= '"mod": "'  . $rs["mod"]  . '",';
  $outp .= '"cat": "'  . $rs["cat"]  . '",'; 
  $outp .= '"com": "'  . $rs["com"]  . '",'; 
  $outp .= '"cru": "'  . $rs["cru"]  . '",'; 
  $outp .= '"for": "'  . $rs["for"]  . '",'; 
  $outp .= '"con: "'   . $rs["con"]  . '",'; 
  $outp .= '"cmt": "'  . $rs["cmt"]  . '"}'; 
  }
  $outp .="]";
  
  $conn-&gt;close();
  
   echo($outp);
  ?&gt;
  </code></pre>