vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Averaging MySQL fields (https://vborg.vbsupport.ru/showthread.php?t=70670)

Jolten 10-16-2004 04:10 PM

Averaging MySQL fields
 
Hi,

I'm trying to write a simple query to retrieve an average of fields in one of my tables.

Code:

$average = $DB_site->query("SELECT AVG(points) FROM usrPoints WHERE atoContId = 662");
I've tried just about everything I can think of or find as far as searching the 'net. The query simply returns a resource ID.

Can anyone help me set the query to actually return a value?

Thanks.

Andreas 10-16-2004 04:33 PM

Maybe

PHP Code:

$average $DB_site->query_first("SELECT AVG(points) AS avgpoints FROM " TABLE_PREFIX "usrPoints WHERE atoContId = 662"); 

and the use $average['avgpoints'] ?

Jolten 10-16-2004 04:37 PM

I don't need the table prefix for my database so I removed that.

But using $average['avgpoints'] does work! Thanks!!!

Andreas 10-16-2004 04:43 PM

I also don't need that in my database.
But it is good coding style to follow vB3 coding standards.
And it makes life easier if you ever have to switch your host(and then maybe have to use prefixes)

Jolten 10-16-2004 07:15 PM

True. :) But if I were to ever need prefixes it would be a week long undertaking to fix the other queries in my custom pages as well. :)

Thanks so much for the assist Kirby. I owe you one.


All times are GMT. The time now is 01:44 PM.

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.01465 seconds
  • Memory Usage 1,714KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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