开发者

PHP: Looping through and displaying data only if it's unique (dates)

I need to display a list of dates from a database. There can be multiple records with the same date,开发者_如何学编程 but I only want the date to display once.

In other words, I need to only display unique dates. Any ideas?


Have you tried using DISTINCT in your sql query?


You can build an array with the date as a key. And the results in tere.

$return = array();

foreach ($results as $result) {
    $return[$result['data']][] = $result;
}

where $return is an array with unique dates as a key.


If your dates are formatted the same you could build an array directly and use array_unique().

http://us3.php.net/manual/en/function.array-unique.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜