SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Mar 23, 2005, 05:36 #1
- Join Date
- Mar 2005
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
DISTINCT in combination with LIMIT
Hi.
I have one little question and try it in my best English.
Can somebody help with this problem:
I have built a Dutch puzzle dictionary and recently I built the 2nd version of it.
There is a big change in the database structure, which is built as the following: (fieldnames are translated in English).
id | description | synonym
-----------------------------
1 | color | blue
2 | color | red
3 | color | green
4 | state of the USA | Oklahoma
5 | state of the USA | Iowa
6 | means of transport | car
7 | means of transport | bicycle
8 | color | white
9 | state of the USA | Arkansas
.....
etcetera
I have written a PHP-script which shows the results, where the synonyms of the same descriptions will be listened as following:
color = blue, green, red, white
means of transport = bicycle, car
state of the USA = Arkansas, Iowa, Oklahoma
Now I want to show only 5 results, so I have to LIMIT it with 5, but if I do so, I get the first 5 results. OK (you should say), but I want to use this way to show the first 5 results, but where the synonyms are the same (as in the example).
Is there a way to LIMIT with DISTINCT?
(I hope you understand what I exactly mean).
-
Mar 23, 2005, 05:50 #2
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$x = "color";
$ret = mysql_query("SELECT * FROM table
WHERE description LIKE '$x'
ORDER BY id LIMIT 5");
while($row = mysql_fetch_array($ret)) {
$y .= $row[2].",";
}
echo $row[1]." = "substr($y, 0, -1);
# echo's ie. color = blue, white, green, purple, red
Bookmarks