The Arcive of vBulletin Modifications Site. |
|
|
#1
|
|||
|
|||
|
I really need a hack that displays the average age. Currently I am using this plugin:
PHP Code:
Andreas/KirbyDE had given me this query instead that is supposed to be more accurate: [sql] SELECT ROUND(AVG(YEAR(NOW())-YEAR(birthday_search) - (MONTH(NOW()) < MONTH(birthday_search)) - (MONTH(NOW()) = MONTH(birthday_search) AND DAY(NOW()) < DAY(birthday_search)))) AS avgage FROM " . TABLE_PREFIX . "user WHERE YEAR(birthday_search)>0 [/sql] but it gives a database error: Code:
Database error in vBulletin 3.5.0: Invalid SQL: SELECT ROUND(AVG(YEAR(NOW())-YEAR(birthday_search) - (MONTH(NOW()) < MONTH(birthday_search)) - (MONTH(NOW()) = MONTH(birthday_search) AND DAY(NOW()) < DAY(birthday_search)))) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0; MySQL Error : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(NOW()) < DAY(birthday_search)))) AS avgage FROM testvb_user WH Error Number : 1064 |
|
#2
|
||||
|
||||
|
try that query
[sql] SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365 AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
|
#3
|
|||
|
|||
|
Thanks so much but I still get a db error...
![]() Database error in vBulletin 3.5.0: Code:
Invalid SQL: SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365 AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;; MySQL Error : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0' a Error Number : 1064 PHP Code:
|
|
#4
|
|||
|
|||
|
Add a ')' in front of the AS avgage.
|
|
#5
|
|||
|
|||
|
Code:
Database error in vBulletin 3.5.0: Invalid SQL: SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;; MySQL Error : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0' a Error Number : 1064 ![]() I have started to think that it will never work out...
|
|
#6
|
||||
|
||||
|
it's just a problem with brackets
![]() [sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW()) / 365))) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
|
#7
|
|||
|
|||
|
Now there is no database error (woo hoo!!
) but...Average Age: -150
|
|
#8
|
||||
|
||||
|
very young users you have
![]() my fault, try that: [sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365)) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] |
|
#9
|
|||
|
|||
|
It looks correct, thanks so much!!!!!!
![]() Another question, not so urgent, answer if and when you have time... How can I make it to display 2 decimals? ![]() Thanks again! Also, do you allow me to release this as a modification? Others may need it too. Of course, I'll include the appropriate credits
|
|
#10
|
||||
|
||||
|
glad we could solve it
![]() 2 decimals are very easy: [sql]SELECT ROUND(AVG(YEAR(NOW()) - YEAR(birthday_search) - (DAYOFYEAR(birthday_search) - DAYOFYEAR(NOW())) / 365), 2) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;[/sql] feel free to release it |
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|