question about Database Methods
#11
(2015-07-14, 09:07 AM)Destroy666 Wrote:
(2015-07-08, 11:15 AM)tempo Wrote: how can i calculate the average of this numbers?

Either use AVG() in your query or fetch and sum the numbers in a while loop and divide them by the number of loop.

(2015-07-08, 11:15 AM)tempo Wrote: how can i display this average before a post?

Either use the plugin I mentioned and insert the code to a proper template or create a standalone plugin..

i'm trying but i something on my code is wrong Huh Huh  ......can you give my the code please.... Smile
Reply
#12
Show what you tried.
Reply
#13
<?php
$query = $db->simple_select("tickets", AVG("air");
$avg = $db->fetch_array($query);
echo $avg;
?>
Reply
#14
At least there is a right bracket missing:


$query = $db->simple_select("tickets", AVG("air"));
Regards, Ad Bakker (NL)
Reply
#15
Also:
1. AVG(...) is a string so it should be enclosed within proper characters.
2. You can't echo an array (well, you can,but it's not what you want).. Use fetch_field() in combination with AS.
Reply
#16
Sorry but I can't understand the syntax about SQL query.
I search about MySQL syntax but there is difference when I use SQL queries into mybb templates.
If you want to help me please give me the code, you can help me to understand the correct syntax.

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)