私はクラスランキング
と DateFilter
を作成しました。
各ランキングクラスには、カットオフ日付を生成する DateFilter
クラスがあります。その日以降に作成されたすべてがテーブルに表示されるようにフィルタを作成できるようにしようとしています。
ただし、比較は機能しません。問題が見えますか?
ここに私のDateFilterクラスがあります:
<?php
include ("Filter.php");
class DateFilter extends Filter
{
//@param daysOld: how many days can be passed to be included in filter
//Ex. If daysOld = 7, everything that is less than a week old is included
private $interval;
public function DateFilter($daysOld)
{
$this->interval = new DateInterval('P'.$daysOld.'D');
}
//@Return: Returns a DateTime that is the earliest possible date to be included in the filter
function createLimitDate()
{
$now = new DateTime();
return $now->sub($this->interval);
}
//generates SQL code for checking date
//Ex. WHERE limitDate > created... if > means before
function genSQL()
{
$limitDate = $this->createLimitDate();
return $limitDate->format('Y-m-d') . " < 'created'";
}
}
?>
そして私のランキングクラス:
<?php
class Rankings
{
private $filter;
//@params: $filty is the filter given to these rankings
public function Rankings($filty)
{
$this->filter = $filty;
}
//@return: returns the html code for the rankings
public function display()
{
echo '<table border="1" align="center">'.
'<tr align="center" style="font-weight:bold;">
<td>#</td><td>NAME</td><td>Date</td>
</tr>
';
//hardcoding DB
$where = $this->filter->genSQL();
$qry = mysql_query("SELECT * FROM `pix`
WHERE $where
");
if (!$qry)
die("FAIL: " . mysql_error());
$i = 1;
while($row = mysql_fetch_array($qry))
{
$name = $row['uniquename'];
$created = $row['created'];
echo ' <tr>
<td>'. $i . '</td>'.
'<td>' . $name . '</td>'.
'<td>'. $created . '</td>'.
'</tr>';
$i += 1;
}
echo '</table>';
echo $where;
}
}
?>
私はそれをこのように呼んでいる:
$test = new DateFilter(100);
$rankings = new Rankings($test);
$rankings->display();
この例では、私のデータベース内のすべてが100日前にアップロードされたと確信していますが、何も表示されません。