Newbie Question, Working With Data
Posted 06 March 2006 - 11:56 PM
This is probably a very easy question to answer, I honestly have no clue. I can work with the very basics of php and slight editing if the code is already there, but I have no clue really on how to go about this.
What I'm trying to do is add all the values stored in a particular column (about 840 values atm and growing), and hopefully divide that number by the total amount. (averaging it). I can do the displaying and such on my own, I have no idea how you would actually get all those numbers to add and such.
Any idea on how one could do this? Thanks for any help!
Posted 07 March 2006 - 12:08 AM
to get averages, sums, and counts, you need to run aggregate functions in your SQL query. don't worry, it sounds a lot harder than it is! ;-)... if i want to find the sum of all the values in one column, i simply can select the SUM() of that column. for instance:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] SUM(points) AS points FROM games; [!--sql2--][/div][!--sql3--]
that sql statement would return only one record containing a column called "points" that holds the value of all the records added together. same thing with average:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] AVG(points) AS points FROM games; [!--sql2--][/div][!--sql3--]
hope that helps!
Posted 07 March 2006 - 04:37 AM
I'm sure that's what I want to be doing (fairly sure), but I can't seem to get it right.
The column I'm looking to average is item_value, which is in eqdkp_items, which is in the database eqdkp.
So how correct is this?
$query="SELECT AVG(points) AS points FROM eqdkp_items";?
I guess I'm having trouble going from eqdkp_items to item_value, which is the one I'd like to average.
Sorry, I'm clueless. Thanks again for the quick reply,
Posted 07 March 2006 - 01:03 PM
$query="SELECT AVG([color=#FF6666]item_value[/color]) AS average FROM eqdkp_items"; $res = mysql_query($query); $av_value = mysql_result ($res, 0, 'average');
Donations gratefully received
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
Posted 07 March 2006 - 10:34 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users