Results 1 to 3 of 3
Thread: php, asc command and limits
Jan 29, 2001, 21:11 #1
I am building an entertainment page for my site. There are several columns in the mysql, one is ent_category.
I want to list the category in assending order: clubs, concerts, etc. There may be 10 clubs that have listings and I want to show the clubs item only once.
Like this: clubs, concerts, opera, symphony,
Not this: clubs, clubs, clubs, concerts, opera, opera, symphony,symphony
So far I have the code working that will give me all the categories.
//query the db
$query = "select ent_category from entertainment"
. " order by ent_category asc";
or die ("Cannot execute query");
But the limit of only one occurance is evading me.
Any Ideas? Thanks
<Edited by edshuck on 01-29-2001 at 10:22 PM>
Jan 29, 2001, 23:26 #2
- Join Date
- May 2000
- 0 Post(s)
- 0 Thread(s)
yay, finally an easy question for the night
$query = "SELECT ent_category FROM entertainment ORDER BY ent_category ASC GROUP BY ent_category";
happy coding!cogito, ergo sum
Jan 30, 2001, 00:32 #3
I had to go off to the laundry and so I took the beginning php4 wrox with me and found another command that may work also.
//query the db
$query = "SELECT DISTINCT ent_category FROM entertainment"
. " ORDER BY ent_category asc";
But your answer provides some more intriqueing possiblities. The idea of notification of the count() to notify the user that there are jazz (7), symphony (2), concert (1). Also I note that the GROUP BY is required when using both field names and aggregate functions.
Thanks for the great answer and moving me to the next level.
I will be making these hot links and when clicked, they will select only the clicked category, order it by date, open or close, format and display it.