title: how to generate and select a dropdown item dynamically using angularjs, php and mysql
body: <p>I have a list of items for a dropdown and I need to generate and select an item which is stored in datatable using angularjs,php and mysql. i already have a code to retrieve items from a datatable and display it in a grid. i need to display the selected item in dropdown with in the grid. </p>
  
  <p>HTML code</p>
  
  <pre><code> &lt;table class="table table-bordered table-striped dataTable" id="grid" aria-describedby="grid_info" style="width: 1307px;"&gt;
   &lt;thead&gt;
     &lt;tr role="row"&gt;
       &lt;th class="sorting_disabled" tabindex="0" rowspan="1" colspan="1" style=" text-align:center"&gt;S.No&lt;a ng-click="sort_by('{{rowRenderIndex+1}}');"&gt;&lt;/a&gt;&lt;/th&gt;
             &lt;th class="sorting_disabled"&gt;Employee&lt;a ng-click="sort_by('empl_name');"&gt;&lt;/a&gt;&lt;/th&gt;
             &lt;th class="sorting_disabled"&gt;Work&lt;a ng-click="sort_by('name');"&gt;&lt;/a&gt;&lt;/th&gt;
             &lt;th class="sorting_disabled center"&gt;Validate&lt;a ng-click="sort_by('status');"&gt;&lt;/a&gt;&lt;/th&gt;
             &lt;th class="sorting_disabled center"&gt;Work Score&lt;a ng-click="sort_by('task_score');"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/th&gt;
        &lt;/thead&gt;
          &lt;tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit"&gt;
            &lt;td class="sorting_disabled"&gt;{{rowRenderIndex+1}}&lt;/td&gt;
            &lt;td class="sorting_disabled"&gt;{{data.empl_name}}&lt;/td&gt;
            &lt;td class="sorting_disabled"&gt;{{data.work}}&lt;/td&gt;
            &lt;td class="center"&gt;&lt;div align="center"&gt;
                &lt;select name=""&gt;                  
                   &lt;option&gt;current&lt;/option&gt; 
                   &lt;option&gt;Incomplete&lt;/option&gt;  
                   &lt;option&gt;completed&lt;/option&gt;
                   &lt;option&gt;Validated&lt;/option&gt;
                &lt;/select&gt;&lt;/div&gt;&lt;/td&gt;
           &lt;td class="sorting_disabled"&gt;{{data.task_score}}&lt;/td&gt;
           &lt;td class="center"&gt;&lt;div align="center"&gt;&lt;input class="inp" type="text" id="{{data.employee}}" name="{{data.employee}}" onblur="" value="{{data.employee_score}}" /&gt;&lt;/div&gt;&lt;/td&gt;
         &lt;/tr&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>var app = angular.module('myApp', ['ui.bootstrap']);
  app.filter('startFrom', function() {
      return function(input, start) {
          if(input) {
              start = +start; //parse to int
              return input.slice(start);
          }
      return [];
     }
  });
  app.controller('workManagement', function ($scope, $http, $timeout) {
  $http.get('workmanagement.php').success(function(data){`enter code here`
      $scope.list = data;
      $scope.currentPage = 1; //current page
      $scope.entryLimit = 5; //max no of items to display in a page
      $scope.filteredItems = $scope.list.length; //Initially for no filter  
      $scope.totalItems = $scope.list.length;
  });
  
  
  $scope.setPage = function(pageNo) {
      $scope.currentPage = pageNo;
  };
  $scope.filter = function() {
      $timeout(function() { 
          $scope.filteredItems = $scope.filtered.length;
      }, 10);
  };
  $scope.sort_by = function(predicate) {
      $scope.predicate = predicate;
      $scope.reverse = !$scope.reverse;
  };
  </code></pre>
  
  <p>});</p>
  
  <p>PHP Code</p>
  
  <pre><code> include('config.php');
  
  $con = mysqli_connect(APP_HOST,APP_USERNAME,APP_PASSWORD);
  mysqli_select_db($con ,APP_DB);
  
  $query="SELECT * FROM workmanagement";
  //$result = $mysqli-&gt;query($query) or die($mysqli-&gt;error.__LINE__);
  $result = mysqli_query($con ,$query);
  
  $arr = array();
  if(mysqli_num_rows($result) &gt; 0) {
      while($row = mysqli_fetch_assoc($result)) {
          $arr[] = $row;
      }
    }
    # JSON-encode the response
    $json_response = json_encode($arr);
  
    // # Return the response
    echo $json_response;
  </code></pre>