php - mysql query of union and mysql_num_rows -


select tbl_post_upvote.id ,        count(user_id) c   tbl_post_upvote    left join tbl_post on (tbl_post.id=tbl_post_upvote.post_id)  tbl_post.author_id = 3 , is_seen = 0  union select tbl_post_downvote.id i,        count(user_id)  tbl_post_downvote   left join tbl_post on (tbl_post.id=tbl_post_downvote.post_id) tbl_post.author_id=3 , is_seen=0     $r_noti = mysql_query($sq_noti);    $l = mysql_fetch_assoc($r_noti);    $l_noti = mysql_num_rows($r_noti);     if ($l['c'] > 0 && $l['i']!=0) { ?>       <span class="badge">           <?= $l_noti; ?>       </span>    <?php } ?> 

it displays result value 6 , 0 , c value 1 , 0 respectively. want remove 0 ,0 row , result value 6 , c value 1 only

you have add group i statements.

please try following:

select tbl_post_upvote.id ,count(user_id) c tbl_post_upvote left join      tbl_post      on (tbl_post.id=tbl_post_upvote.post_id) tbl_post.author_id=3 , is_seen=0 group union select tbl_post_downvote.id i,count(user_id) tbl_post_downvote left join      tbl_post      on (tbl_post.id=tbl_post_downvote.post_id) tbl_post.author_id=3 , is_seen=0 group 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -