如何从mysql删除重复的年份和月份到PHP?

时间:2014-10-29 03:36:27

标签: php mysql

我只是想知道如何从下面的代码中删除重复的年/月。

//Function to return unique year for index menu:

function get_year()

{

$date = months_years();
while ($row = mysqli_fetch_array($date)){
    $rows[]= explode('-', $row['date']);
}
foreach ($rows as $row){
    $y[] = $row;
}
for ($e = 0; $e < count($y); $e++)
{
    $duplicate = null;
    for ($ee = $e+1; $ee < count($y); $ee++)
    {
        if (strcmp($y[$ee][0],$y[$e][0]) === 0)
        {
            $duplicate = $ee;
            break;
        }
    }
    if (!is_null($duplicate))
        array_splice($y,$duplicate,1);
}
foreach ( $y as $k=>$v)
{
    $y[$k] ['year'] = $y[$k][0];unset($y[$k][0]);
    $y[$k] ['months'] = $y[$k][1];unset($y[$k][1]);
    $y[$k] ['day'] = $y[$k][2];unset($y[$k][2]);
}
foreach ($y as $k)
{
    extract($k);
    echo "<a href='index.php?year=".$year."&month=".$_GET['month']."'title='Select Year to Display'>".$year."</a> ";
    }
}

输出:

日历

1970 2014 2014 2014 2014 2014 2014

01 08 09 09 09 09 10 10

谢谢并希望有人可以帮助我。

0 个答案:

没有答案