开发者

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

开发者 https://www.devze.com 2023-01-10 19:17 出处:网络
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.

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

精彩评论

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