SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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";

    $result= mysql_query($query)
    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>

  2. #2
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    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

  3. #3
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Vinay,

    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.

    Thanks again

    peace


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •