SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Beginner Question: Select from table

    THis is a very beginner question.

    I have a my-sql table (class-ads). There three fields: member-id, date, and ads. One member-id can post several ads. Now I want to create a page to show this "member-id" have this "total ads".

    Can someone give idea the mysql/php statement to do that.

    Thanks alot.

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here you go:

    SELECT COUNT(*) FROM class-ads WHERE member-id = [theMemberId/variable]
    John

  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks PHP John,

    I think I was not so clear.

    What I need to list in a page is like this:

    member-id Total Ads
    001 7
    002 8


    Thanks

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off the top of my head and untested
    Code:
    SELECT member-id, COUNT(ads) AS totalads
    FROM class-ads
    GROUP BY member-id
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  5. #5
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Anode


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
  •