Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-12-2005, 06:46 AM
Lea Verou Lea Verou is offline
 
Join Date: Jul 2005
Location: Greece
Posts: 1,856
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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!
Reply With Quote
  #2  
Old 10-12-2005, 12:09 PM
-=Sniper=- -=Sniper=- is offline
 
Join Date: May 2002
Posts: 605
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Attached Files
File Type: xml avg-plugin.xml (395 Bytes, 13 views)
Reply With Quote
  #3  
Old 10-12-2005, 12:22 PM
Lea Verou Lea Verou is offline
 
Join Date: Jul 2005
Location: Greece
Posts: 1,856
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 Maybe a male to female ratio I guess

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
Reply With Quote
  #4  
Old 10-12-2005, 12:39 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 10-12-2005, 12:41 PM
-=Sniper=- -=Sniper=- is offline
 
Join Date: May 2002
Posts: 605
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 
Reply With Quote
  #6  
Old 10-12-2005, 12:43 PM
Lea Verou Lea Verou is offline
 
Join Date: Jul 2005
Location: Greece
Posts: 1,856
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 )
Reply With Quote
  #7  
Old 10-12-2005, 12:48 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@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.
Reply With Quote
  #8  
Old 10-12-2005, 12:49 PM
Lea Verou Lea Verou is offline
 
Join Date: Jul 2005
Location: Greece
Posts: 1,856
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Reply With Quote
  #9  
Old 10-12-2005, 12:58 PM
-=Sniper=- -=Sniper=- is offline
 
Join Date: May 2002
Posts: 605
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

as strange as it might sound thats whole error message I get, I just tested it a couple of times.
Reply With Quote
  #10  
Old 10-12-2005, 01:00 PM
Lea Verou Lea Verou is offline
 
Join Date: Jul 2005
Location: Greece
Posts: 1,856
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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??
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:36 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.04178 seconds
  • Memory Usage 2,274KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete