私は角度と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);
}
}
}
});
あなたは 'GROUP BY月 'または' WHERE row.date = @ month'をしますか?サンプルデータの現在および期待される結果を表示します。 [** How-to-Ask **](http://stackoverflow.com/help/how-to-ask) \t \t [** START **](http ://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)質問品質を向上させ、より良い回答を得る方法を学ぼう。 –
@JuanCarlosOropezaのヒントのおかげで。月を選択してその特定の月のすべてのデータを取得したい – tanyaa
[AngularJsでフィルタリングする方法(フィルタで月別にフィルタリングする方法)](http://stackoverflow.com/questions/29241696/how-to-filter-by -month-in-angularjs-with-filter) –