私のコードのアイデアは、特定の月と年に発生したテーブル内のすべての更新された行を取得することです。そのため、月と年を表示する2つのドロップダウンメニューがあり、月と年を選択すると、選択した月と年に発生したすべての更新された行が表示されます。この問題を解決するアイデアを手伝ってくれる人はいますか?ヒント: データベースに保存されている日付は (Ymd) の形式です。
2 に答える
            0        
        
		
ヒント: ヒントを与えるのではなく、全体の話をしてください。
問題の可能な解決策 (php 5.3+ で動作します):
<?php
  $startDate = date("Y-m-d", strtotime("first day of the month", strtotime( (int) $_POST['year']."-".(int)$_POST['month'].-"01 00:00")));
  $endDate = date("Y-m-d", strtotime("last day of the month", strtotime( (int) $_POST['year']."-".(int)$_POST['month'].-"01 23:59")));
  $db = ; //your PDO connection
  $q = $db->prepare("SELECT `thingstoselect` FROM `yourtable` WHERE `date` > ? && `date` < ?");
  $q->execute( array( $startDate, $endDate));
  $yourResults = $q->fetchAll();
    于 2012-11-12T22:40:47.680   に答える
    
    
            0        
        
		
varchar または日付として保存していますか?
日付列として保存している場合は、 $year 変数と $month 変数を次のものと比較できます。
select * from TABLE where year(datecol) > $year or (year(datecol) = $year and month(datecol) >= $month);
部分文字列の場合は、より大なりの奇妙な変換を行う必要がありますが、部分文字列を使用して正確な一致を見つけることができます。
select * from TABLE where substring_index(stringcol,'-',1) > $year or ( substring_index(stringcol,'-',1) = $year and substring_index(substring_index(stringcol,'-',2),'-',-1) >= $month );
問題は、MySQL に文字列分割機能が組み込まれていないことです。
于 2012-11-12T22:42:23.293   に答える