SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast MaRkY's Avatar
    Join Date
    Dec 2001
    Location
    Spain
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with COUNT

    My question is very short:

    Is there anyway to display 0 results on mysql COUNT function?

  2. #2
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not entirely clear on what you mean. The COUNT function should return 0 if no records match the criteria (e.g. the statement:

    SELECT COUNT(*) FROM TABLE_NAME WHERE 1 = 0

    would return 0).

    If this isn't happening, then it's possible your query is excluding the rows in some way - for example, if you're joining several tables you may be exluding the rows you wish to have returned as a 0.

    Could you please specify your problem more clearly, or perhaps post the query you're having problems with and explain exactly what you expect to be returned, and what is actually being returned?

  3. #3
    SitePoint Enthusiast MaRkY's Avatar
    Join Date
    Dec 2001
    Location
    Spain
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oki thanks for the fast answer

    The problem is the following, i got a table of buildings, and there is a typeid of diferent kind of buildings.

    Letīs say:

    typeid = 1 = House
    typeid = 2 = Flat

    I want to count all buildings from a date given, and I get the following result:

    House 1
    Flat 5

    But there are like 5 kind of buildings more, and I want to display them with 0, and they doesnīt appear.

    How can I make that the rest of buildings appear with 0?

  4. #4
    SitePoint Enthusiast MaRkY's Avatar
    Join Date
    Dec 2001
    Location
    Spain
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed, and sorry

    Itīs imposible to count values when they doesnīt exist

    Big Mistake.

  5. #5
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it fixed, and don't worry - I make far larger mistakes fairly regularly (usually with live data too ).

    Cheers.
    Nick Wilson [ - email - ]


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
  •