-1

I have a database from which I call data according to checkboxes checked(Retrieve data from sql database and display in tables - Display certain data according to checkboxes checked). I want to add an option of calculating their average (Between the wanted dates). How can I write a query, calculating the averages when the output is not something specific?

This is the query that calls my data at first place:

$tmp ="SELECT DISTINCT ".implode(",", $sql_columns)." FROM $database_Database_Test.$table_name where DATE>=\"$fromdate\" AND DATE<=\"$todate\"";

How can the average-query call the data according to checkboxes checked + don't average the date and hour column:

$average="SELECT AVG(",", $sql_columns) AS PriceAverage FROM $database_Database_Test.$table_name where DATE>=\"$fromdate\" AND DATE<=\"$todate\""; 

Here is my attempt but don't seem to work. The problem is that the AVG is for strings and I want to display an array.

Community
  • 1
  • 1
Lef_Chef
  • 19
  • 1
  • 8
  • Table in the text file is just a fancy formatted text. But you will need to control spacing and dimensions of table cells. And, of course, you'll have to use some kind of ASCII graphics for borders: "|" and "_" symbols, for example. – Gino Pane May 13 '14 at 08:42
  • though it is rather straightforward, but you can firstly detect the longest text value in a single column - it will be current column width. Then, when writing a value to the column, you will use approach like this: `"|".$some_spaces_left.$value.$some_spaces_right."|"`, where `$some_spaces_left` and `$some_spaces_right` are text margins, to keep text centered. And also keep in mind borders at the edges. But, actually, you can also do everything without borders at all, just format columns with spaces. – Gino Pane May 13 '14 at 09:20

1 Answers1

0

Firstly you state a variable that matches your columns [inside the parenthesis e.g (DNI)] and give the command to calculate their average. Finally name the average e.g 'adni'.

$avg_names=array('1'=>'AVG(DNI) as adni', '2'=>'AVG(GHI) as aghi', '3'=>'AVG(Zenith_Angle) as azenith', '4'=>'AVG(DiffuseHI) as adhi');

$average="SELECT ".implode(",", $avg_names)." FROM $database_Database_Test.$table_name where DATE>=\"$fromdate\" AND DATE<=\"$todate\""; 
Lef_Chef
  • 19
  • 1
  • 8