私はWordpress機能を実装しており、PHPを使用して年と月ごとに投稿を表示しています
例えば:
プレスリリース
2013年(4)
10月(1)
発表1
しかし、結果で繰り返される各レコードを取得しています。コードは次のとおりです。
$query = "SELECT * FROM edu_announcements WHERE status = '1' ORDER BY add_time asc";
$resultSet = mysql_query($query);
if (mysql_num_rows($resultSet))
{
$newsArray = array();
echo '<ul>' . PHP_EOL;
echo '<li><strong>Press releases:</strong></li>' . PHP_EOL;
while ($newsResult = mysql_fetch_array($resultSet))
{
$newDate = $newsResult['add_time'] ;
$timePeriod =date("F Y", $newDate);
//$timePeriod = date('F Y ',strtotime($newDate));
$timePeriodY = date('Y',$newDate);
$timePeriodM = date('F',$newDate);
if (!isset($newsArray[$timePeriod]))
{
$newsArray[$timePeriod] = array();
}
$newsArray[$timePeriod][] = $newsResult;
}
foreach ($newsArray as $timePeriod => $newsItems)
{
$timePeriodY = date('Y',strtotime($timePeriod));
echo '<li><strong>' . $timePeriodY . '</strong>' . PHP_EOL;
echo '<ul>' . PHP_EOL;
//by month
foreach ($newsArray as $timePeriod => $newsItems)
{
echo '<li><strong>' . $timePeriod . '</strong>' . PHP_EOL;
echo '<ul>' . PHP_EOL;
//news items
foreach ($newsItems as $item)
{
echo '<li>';
echo '<a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php">'.$item["title"].'</a>';
echo '</li>' . PHP_EOL;
}
//end by month
echo '</ul>' . PHP_EOL;
echo '</li>' . PHP_EOL;
}
//end by year
echo '</ul>' . PHP_EOL;
echo '</li>' . PHP_EOL;
}
echo '<li> </li>' . PHP_EOL;
echo '</ul>' . PHP_EOL;
}
else {
echo 'No announcements';
}
以下に示すように、結果が繰り返されます。
Array ( [July 2013] => Array ( [0] => Array ( [0] => 99 [id] => 99 [1] => sdfsdf [title] => sdfsdf [2] =>
sdfsdfsdfc
[description] =>
sdfsdfsdfc
[3] => [documents] => [4] => [photo1] => [5] => [photo2] => [6] => [photo3] => [7] => [photo4] => [8] => 1 [public_visibility] => 1 [9] => 0 [dept_visibility] => 0 [10] => 0 [depatment] => 0 [11] => 1373913000 [add_time] => 1373913000 [12] => 1 [status] => 1 [13] => sdfsdf [small_description] => sdfsdf ) [1] => Array ( [0] => 100 [id] => 100 [1] => sefsdfvsxdf [title] => sefsdfvsxdf [2] =>
sdfsdfsd
[description] =>
sdfsdfsd
[3] => [documents] => [4] => [photo1] => [5] => [photo2] => [6] => [photo3] => [7] => [photo4] => [8] => 1 [public_visibility] => 1 [9] => 0 [dept_visibility] => 0 [10] => 0 [depatment] => 0 [11] => 1374604200 [add_time] => 1374604200 [12] => 1 [status] => 1 [13] => sdfsefs [small_description] => sdfsefs ) )
テーブルとは異なるレコードが必要です。誰でもこれを解決するのを手伝ってもらえますか?