The Arcive of vBulletin Modifications Site. |
|
|
#1
|
||||
|
||||
|
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 .
|
|
#2
|
||||
|
||||
|
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... |
|
#3
|
||||
|
||||
|
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
.
|
|
#4
|
||||
|
||||
|
Quote:
PHP Code:
|
|
#5
|
||||
|
||||
|
I think i see a typo in that..
|
|
#6
|
||||
|
||||
|
PHP Code:
aranoid:
|
|
#7
|
||||
|
||||
|
The code above will give you a very nice error. My code is correct.
|
|
#8
|
||||
|
||||
|
Yes. Indeed. A VERY nice error.. Hey, cant hate me cause im trying
|
|
#9
|
||||
|
||||
|
That's how we all learn, by doing mistakes.
![]() Cheers. |
|
#10
|
||||
|
||||
|
hehe... :OI I just seen that '(' and was thinking.. 'whoa dont it have to be the other way?'.. But i was wrong
|
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|