![]() |
Howto limit same results to one?
Hi all!
How do I limit same results to as one?! example: if my query fetch like this: Code:
BananaCode:
BananaThanks for all help! |
Are you fetching the list from a database? If so, there are a couple of options you can use.
The first is to use the DISTINCT keyword in your query: SQL Code:
The second is to use the GROUP BY clause in your query: SQL Code:
Both will give you the desired result :-) Alan |
Hi Alan and thanks 4 replying.
Yes I'm fetching these from database (sorry for not metion that ;)) Amm.. What if I don't know which results will be multiple at the time I'm coding this? Or then I didn't quite understand your examples? Well let's bake one example this way. I have news-script where is several posts for each month. I want to create archive links for each those months, automaticly ofcourse.. I would do it something like this: PHP Code:
Maybe your example Alan works but I have now clue how I should do it? Thanks for all help! =) |
In your example above I would move the unique check to the PHP code.
For example, instead of print()'ing your date links, I would add them to an array and then use array_unique() on it to strip out duplicates.Something like the following (untested) should work: PHP Code:
|
Whau.. You are gooood Alan!! =)
Thank You! ^^ |
Glad I could help :-)
Alan |
If the type of the
added column is DATE or DATETIME you can do it with a simple query:SQL Code:
This will return a table like this: Code:
+--------+ +------+PHP Code:
SQL Code:
|
| All times are GMT. The time now is 07:24 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0