2016-08-18 4 views
1

저는 각도와 PHP로 프로젝트를 만들고 있습니다. 나는 특정 날짜를 선택하는 "선택"옵션을 가지고 있으며 테이블의 모든 세부 사항을 보여 주며 여러 가지를 고려하면 모든 것이 훌륭하게 작동합니다. 하지만 날짜를 선택하면 특정 날짜가 아니라 특정 월별로 모든 결과를 표시하고 싶습니다 (예 : -> 지금 내가이 날짜를 선택합니다 - '2016-4-15'). 이 날짜와 내가 필요로하는 것처럼 달에 의해). 누군가 도와 주실 수 있습니까? 내 데이터베이스에서 '날짜'값은 날짜입니다.각도로 날짜를 필터링하는 방법은 무엇입니까?

PHP는 쿼리 :

$query=" SELECT `description` ,`total_price` , `name`,`supplier_id`,`date` FROM `suppliers`,`expenses` 
    where `supplier_id` = `refer_supplier_id` "; 

HTML :

<select ng-model="supplierExpenses.selectedOption" ng-change="setTotals(supplierExpenses)" 
     ng-options = "item.date for item in supplierExpenses | 
     unique:'date'" > 

     <option value="">בחר תאריך</option> 
     </select> 



<div class="table-responsive"> 
<table class="customer-list table table-striped" > 
      <thead> 
       <tr > 

        <th class="Column-Header">מספר ספק</th> 
        <th class="Column-Header">שם ספק</th> 
        <th class="Column-Header">כמות מוצרים שנקנו</th> 
        <th class="Column-Header">מחיר הוצאה</th> 

       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="item in supplierExpenses" ng-if = "item.date == supplierExpenses.selectedOption.date" 
        > 

        <td>{{item.supplier_id}}</td> 
        <td>{{item.name}}</td> 
        <td>{{item.description}}</td> 
        <td>{{item.total_price}}</td> 

       </tr> 
      </tbody> 
      <tfoot> 

       <tr class="bg-warning"> 
        <td><font size="6">סה"כ הוצאות</font></td> 
        <td><font size="6">{{totalExpenses}}</font></td> 
        <td></td> 
       </tr> 
      </tfoot> 

     </table> 


</div> 

컨트롤러 : 나는 ^에 대한 작업 솔루션으로 내 대답을 편집하면 총 성공

"use strict"; 
angular.module('dataSystem').controller('supplierExpensesCtrl', function ($scope, $route, $location, $http) { 
    $http({method:'GET', url:'api/reports-tab/supplier-expenses-by-mounth.php/'}) 
     .then(function(response) { 
     var arr = JSON.parse(JSON.parse(response.data)); 
     $scope.supplierExpenses = arr; 
     }) 

     // This will log you the error code and trace, if there is an error. 
     .catch(function(err) { 
     console.log('err', err) 
     }); 

     $scope.totalExpenses = 0; 
     $scope.setTotals = function(totalItem){ 
     $scope.totalExpenses = 0; 
     for(var item =0; item< totalItem.length; item++){ 
      // console.log(totalItem[item]); 
      if (totalItem[item] && (totalItem[item].date == $scope.supplierExpenses.selectedOption.date)){ 

      $scope.totalExpenses += parseInt(totalItem[item].total_price); 
      } 
     } 
    } 
}); 
+0

'GROUP BY 월'또는 'WHERE row.date = @ month'를 원하십니까? 샘플 데이터 현재 및 예상 결과를 보여줍니다. [** How-to-Ask **] (http://stackoverflow.com/help/how-to-ask) \t \t 그리고 [** 시작 **] (http : //spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/) 질문 품질을 향상시키고 더 나은 답변을 얻는 방법을 배우십시오. –

+0

@JuanCarlosOropeza 팁 주셔서 감사합니다. 한 달을 선택하고 해당 월의 모든 데이터를 가져 오려고합니다 – tanyaa

+0

[AngularJs에서 필터로 달별 필터링하는 방법] 가능한 복제본 (http://stackoverflow.com/questions/29241696/how-to-filter-by -month-in-angularjs-with-filter) –

답변

1

안녕 기쁘다 발행일

$http({method:'GET', url:'api/reports-tab/supplier-expenses-by-mounth.php/'}) 
     .then(function(response) { 
      var arr = JSON.parse(JSON.parse(response.data)), month, date; 
      for(var i = 0; i< arr.length; i++){ 
       date = new Date(arr[i].date); //we convert the string into javascript date 
       month = date.getMonth()+1; 
       if(month.length === 1){ 
        month = '0'+month; //we add a 0 if needed 
       } 
       var year = date.getFullYear(); 
       arr[i].date = month+'/'+year; //we use only the month and year 
      } 
      $scope.supplierExpenses = arr; 

     }) 
+0

안녕하세요 !! 덕분에 지금 시도해 보겠습니다. – tanyaa

+0

작동하지 않습니다. (테이블이 날 선택없이 표시됩니다.) – tanyaa

+0

무엇이 잘못 될 수 있는지 확인하기 위해 formatedDate() 함수를 추가 할 수 있습니까? – DMCISSOKHO

관련 문제