title: AngularJS - ng-repeat multiple radio button groups, values to array
body: <p>I am having trouble retrieving the values from multiple groups of radio buttons.  Ideally, I would like to store the selected radio buttons in an array and insert them into a database.  I'm getting hung up on what to use for the ng-model inside the ng-repeat, as I believe each radio button group should have its own ng-model attribute.</p>
  
  <p>Here is my html:</p>
  
  <pre><code>        &lt;table id="p4c-table" class="table table-striped table-responsive"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;FAVORITE&lt;/th&gt;&lt;th&gt;POINTS&lt;/th&gt;&lt;th&gt;UNDERDOG&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr ng-repeat="game in games"&gt;
                      &lt;td&gt;
                          &lt;div class="switch-field"&gt;
                              &lt;img class="logo-left remove" src="./assets/img/logos/{{ game.fav_sn }}.gif" alt="{{ game.favorite }}"&gt;
                              &lt;input id="{{ game.fav_nickname }}" type="radio" value="{{ game.fav_nickname }}" name="{{ game.game_id }}" /&gt;
                              &lt;label for="{{ game.fav_nickname }}" class="hvr-box-shadow-inset pull-right"&gt;{{ game.fav_nickname }}&lt;/label&gt;    
                          &lt;/div&gt;
                      &lt;/td&gt;
                      &lt;td class="text-center"&gt;{{ game.points }}&lt;/td&gt;
                      &lt;td class="text-right"&gt;
                          &lt;div class="switch-field"&gt;
                              &lt;input id="{{ game.und_nickname }}" type="radio" value="{{ game.und_nickname }}" name="{{ game.game_id }}" /&gt;
                              &lt;label class="hvr-box-shadow-inset" for="{{ game.und_nickname }}"&gt;{{ game.und_nickname }}&lt;/label&gt;
                              &lt;img class="logo-right remove" src="./assets/img/logos/{{ game.und_sn }}.gif" alt="{{ game.underdog }}"&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/tbody&gt;
              &lt;tfoot&gt;
                  &lt;tr&gt;&lt;th colspan="5"&gt;&lt;i&gt;Home teams capitalized in bold&lt;/i&gt;&lt;/th&gt;&lt;/tr&gt; 
              &lt;/tfoot&gt;
          &lt;/table&gt;
  </code></pre>
  
  <p>Here is my app.js file:</p>
  
  <pre><code>(function() {
  
  var app = angular.module("app", ['ngRoute']);
  
  app.config(function($routeProvider) {
      $routeProvider
          .when('/', {
              templateUrl: 'templates/home.html'
          })
          .when('/picksheet', {
              templateUrl: 'templates/picksheet.html',
              controller: 'PicksheetController'
          })
          .otherwise({
              redirectTo: '/'
          });
  });
  
  }());
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>(function() {
  
  var application = angular.module('app');
  var PicksheetController = function($scope, $http, $log) {
  
      $http.get('./resources/picksheet.php')
          .success(function(data) {
              $scope.games = data;
              console.log(data);
          })
          .error(function(err) {
              $log.error(err);
          })
  
  }
  
  application.controller("PicksheetController", PicksheetController)
  
  }());
  </code></pre>
  
  <p>Here is my picksheet.php file:</p>
  
  <pre><code>&lt;?php
  
  include __DIR__ . '\config.php';
  
  $conn = new mysqli($host, $user, $pass, $db);
  
  if($conn-&gt;connect_errno) {
      die("Database Connection failed:" . $conn-&gt;connect_errno);
  }
  
  $sql = 'SELECT A.game_id, B.team_nickname AS fav_nickname, fav_sn, C.team_nickname AS und_nickname, und_sn, points, favorite, underdog
          FROM p4c_games A
          JOIN p4c_teams B ON A.favorite = B.team_fn
          JOIN p4c_teams C ON A.underdog = C.team_fn
          JOIN p4c_current_week_season D ON A.week = D.week AND A.season = D.season
          ORDER BY A.game_id';
  
  $qry = $conn-&gt;query($sql);
  
  $data = array();
  
  if($qry-&gt;num_rows &gt; 0) {
      while($row = $qry-&gt;fetch_object()) {
          $data[] = $row;
      }
  } else {
      $data[] = null;
  }
  
  $conn-&gt;close();
  
  echo json_encode($data);
  ?&gt;
  </code></pre>
  
  <p>Here is a <a href="https://jsfiddle.net/dpguthrie/qhm12xce/" rel="nofollow noreferrer">fiddle</a>.</p>