Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThank you for the quick response. I have three questions regarding your answer: 1. Can you please explain "COUNT(IF(ISNULL(pv.private_id) AND p.private<>'0' AND p.user_id<>'1', null, 1))" in detail? It seems to work but I can't figure out what all the parts do/mean. 2. If we use $logged_in_id as 7, which doesn't exist. We still get results. Does this make sense? Also, what if a user is logged out, so $logged_in_id='', would the query be the same? 3.If not using the threads table, I feel the counting will be too heavy on each page reload. Do you suggest this as the most efficient solution?
      singulars
    2. CO**1.** **COUNT()** will count records where the content of the function is not null. That is what the **IF(,null,1)** is for. **2.** Added af join to users as 'auth' to do authentication. This will return 0 records if user not logged in (both '7' and '') **3.** Yes I agree if the number of posts will be become large over time, then I would prefer maintaining a count rather than query it every time.
      singulars
    3. COFor easier readability and logic I turned the IF into a CASE like this: COUNT(case when ISNULL(pv.private_id) AND p.private='1' AND p.user_id='3' then null else 1 end) Is this correct? Instead of p.private<>'0', and p.user_id<>'1' (as there will be more than users 1 & 3), I put the above p.private='1', and p.user_id='3'. Also, why would it mess up the count id we put 0 instead of null in the then else?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload