![]() |
MySQL query help please
Here is my current MySQL query...
SELECT SUM(hitscount) AS totalhits FROM hits WHERE time>123456789 AND siteid=10 GROUP BY siteid This query works great most of the time, but sometimes there won't be any result rows that match the criteria. How would I make totalhits be equal to 0 if there are no results returned instead of a mysql resource result with no rows? Thanks for you help :). |
this part here is useless if it's the full query:
AND siteid=10 GROUP BY siteid just remove the group by and i think it should work... |
I realized that I was needlessly added in the SUM() part that was already taken care of by the grouping, so it was repetative. The solution I can up with on my own (using mysql_num_rows()) isn't nearly as elegant as merely removing the group by part and using intval() on the result. Thanks for you help :).
|
Quote:
PHP Code:
|
I think i see a typo in that..
|
PHP Code:
|
The code above will give you a very nice error. My code is correct.
|
Yes. Indeed. A VERY nice error.. Hey, cant hate me cause im trying ;)
|
That's how we all learn, by doing mistakes. :)
Cheers. |
hehe... :OI I just seen that '(' and was thinking.. 'whoa dont it have to be the other way?'.. But i was wrong :(
|
All times are GMT. The time now is 11:00 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|