vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Average age in statistics (https://vborg.vbsupport.ru/showthread.php?t=98199)

Lea Verou 10-12-2005 06:46 AM

Average age in statistics
 
I would like to include an average age in statistics.
I want to make it as a mod and release it here (i love seeing people liking my "hacks" and installing them!!) but I have a very little php knowledge and none for SQL. I can learn easily though!
I just want somebody who knows to point me to the right direction and give me some guidelines, especially on the SQL part.
I read about a SQL function AVG, will it help?
Can I make this as a plugin?
I have never made a code mod before, only template mods, but I really like giving to the community. I just need some help with this as it looks quite difficult to me...
I took a look at my database and as I expected there is no "age" field, just birthday. This means my script should calculate the age itself or vb provides a way to do so?
Any help is really appreciated!! :)

Thanks in advance!

-=Sniper=- 10-12-2005 12:09 PM

1 Attachment(s)
this is from my site www.hardwareforums.com

import the attached plugin (enable it is well) and in your forumhome template search for

PHP Code:

$vbphrase[welcome_to_our_newest_member_x]</phrase></div

and add this after it

Average Age: $avg_age

I'm sure it can be done without any template edits, so if someone wants to, feel free to turn it into that...

Lea Verou 10-12-2005 12:22 PM

Thanks so much! Why don't you release this as a plugin? It's a nice idea I think and it would get many installs! :)

PS: I guess now I must find something else to make as my first php-hack :p Maybe a male to female ratio I guess :p

It produced a database error cause it tried to SELECT from a table that didn't exist. For some reason it treated the database name as the prefix as well.
I'll look into the code and try to see if I can fix it although I consider it quite unlikely :p

Andreas 10-12-2005 12:39 PM

I'd use another query:
[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 user WHERE YEAR(birthday_search)>0
[/sql]
as your Version only looks for the year, which produces incorrect results.

-=Sniper=- 10-12-2005 12:41 PM

thanks KirbyDE I'll update it now

edit:I get this msg

PHP Code:

#1064 - 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 user W 


Lea Verou 10-12-2005 12:43 PM

1. Both of your queries don't consider the prefix I think (correct me if I'm mistaken, I don't know SQL)

2. I would prefer the average to have 1-2 decimal digits, not as an integer like it does now

(I hope my english makes sense :p)

Andreas 10-12-2005 12:48 PM

@Sniper
This doesn't seem to be a complete mySQL erorr message

@Loukrhtia
I just posted the query, no PHP Code. And pure queries can't contain the TABLE_PREFIX constant :)
But you're right, in PHP one must add it.

If you want decimals, leave out the ROUND() and run the result through vb_number_format(), with decimals set to 2.

Lea Verou 10-12-2005 12:49 PM

I made the query like that so that it has the prefix:
[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 I get another database error now:

Quote:

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 vb3_ 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 vb3_ user WHER
Error Number : 1064
at least now the prefix is ok :surprised:

-=Sniper=- 10-12-2005 12:58 PM

as strange as it might sound thats whole error message I get, I just tested it a couple of times.

Lea Verou 10-12-2005 01:00 PM

Quote:

Originally Posted by -=Sniper=-
as strange as it might sound thats whole error message I get, I just tested it a couple of times.

Looks like we are getting the same error message Sniper...
KirbyDE, any ideas??


All times are GMT. The time now is 02:08 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
  • Page Generation 0.01115 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete