0

I just want to know how to remove duplicate Year/Month from the code below.

//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> ";
    }
}

OUTPUT:

Calendar

1970 2014 2014 2014 2014 2014 2014

01 08 09 09 09 09 10 10

Thanks and Hoping someone could help me.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Look over this Raymond. It may solve your removal problem http://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql – PureData1 Oct 29 '14 at 03:41
  • Hi sgt. thanks for the quick reply. I've done the code you post but it only doubles the existing output. Hi PureData1, thanks also for your reply. I currently reading the link that you gave to me. Can the code be changed to a more simple one but same result (no duplicate)? Sorry for the dumb question. I'm only starting to learn php-mysql coding. Thanks again to both of you. – Raymond Samonte Oct 29 '14 at 06:21

0 Answers0