Jump to content

Recommended Posts

I am performing a query in my database to fetch information, and count how many of a specific type of articles there are. My database stores 3 types of articles, a review, preview and article - however, if one of them counts a zero value, it does not show the entry.

 

ie:

if I have 3 reviews, 4 previews and 1 article it will show.

But it I have 3 reviews, 0 previews and 1 article it wont show (or what ever combination of items = zero)

 

how can I fix this?

 

here is my code:

 

COUNT(articles_1.type) AS reviews, COUNT(articles.type) AS previews, COUNT(articles_2.type) AS articles

this extract counts the types of articles such as review, preview or just a normal article

 

SELECT
  product.screenshots, product.renders, product.moreimages, product.ytplaylist, product.minreq, product.download, COUNT(articles_1.type) AS reviews, COUNT(articles.type) AS previews, COUNT(articles_2.type) AS articles, product.title
FROM
  inf81_product.product
  INNER JOIN inf81_product.categories ON categories.id = product.cat
  INNER JOIN inf81_product.articles ON articles.game = product.id
  INNER JOIN inf81_product.articles articles_2 ON articles_2.game = product.id
  INNER JOIN inf81_product.articles articles_1 ON articles_1.id = product.id
WHERE
  categories.slug = '$var1' AND product.slug = '$var2' AND articles.type = 'review' AND articles_1.type = 'preview' AND articles_2.type = 'article'
GROUP BY
  product.id
LIMIT
  1

Link to comment
https://forums.phpfreaks.com/topic/205627-query-results-empty-if-count-0/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.