Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop Through all tables in Mysql database and get Average of identical columns from each table in PHP
    primarykey
    data
    text
    <p>Apologies in advance for the table structure...but I have multiple tables each pertaining to a different user's collected data. That data is collected continuously and just adds more rows as it happens... As I've said I have multiple tables with this similar structure and I would like to end up with an average value over 10 groups of 5 colums. (fb1 + fb2 + fb3 + fb4 + fb5)/5 = average for q's 1-5....</p> <p>The Columns each refer to an answer derived from a web application survey and are all valued from 1-10. These questions are in groups of 5 and are added together then devided by 5 for an average value....</p> <p>What I want is this, but looping over all of the columns from all of the tables and getting the same result on a grander scale.</p> <p>I have the formula for this per table as seen below, but how can i loop over an unset number of tables to output the same values taking into account values from multiple tables?</p> <pre><code> $query="SELECT AVG(fb1), AVG(fb2), AVG(fb3), AVG(fb4), AVG(fb5), AVG(fb6), AVG(fb7), AVG(fb8), AVG(fb9), AVG(fb10), AVG(fb11), AVG(fb12), AVG(fb13), AVG(fb14), AVG(fb15), AVG(fb16), AVG(fb17), AVG(fb18), AVG(fb19), AVG(fb20), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb5), AVG(fb21), AVG(fb22), AVG(fb23), AVG(fb24), AVG(fb25), AVG(fb26), AVG(fb27), AVG(fb28), AVG(fb29), AVG(fb30), AVG(fb31), AVG(fb32), AVG(fb33), AVG(fb34), AVG(fb35), AVG(fb36), AVG(fb37), AVG(fb38), AVG(fb39), AVG(fb40), AVG(fb41), AVG(fb42), AVG(fb43), AVG(fb44), AVG(fb45), AVG(fb46), AVG(fb47), AVG(fb48), AVG(fb49), AVG(fb50) FROM `".$_SESSION['table']."`"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $row1 = $row['AVG(fb1)'] + $row['AVG(fb2)'] + $row['AVG(fb3)'] + $row['AVG(fb4)'] + $row['AVG(fb5)']; $row2 = $row['AVG(fb6)'] + $row['AVG(fb7)'] + $row['AVG(fb8)'] + $row['AVG(fb9)'] + $row['AVG(fb10)']; $row3 = $row['AVG(fb11)'] + $row['AVG(fb12)'] + $row['AVG(fb13)'] + $row['AVG(fb14)'] + $row['AVG(fb15)']; $row4 = $row['AVG(fb16)'] + $row['AVG(fb17)'] + $row['AVG(fb18)'] + $row['AVG(fb19)'] + $row['AVG(fb20)']; $row5 = $row['AVG(fb20)'] + $row['AVG(fb22)'] + $row['AVG(fb23)'] + $row['AVG(fb24)'] + $row['AVG(fb25)']; $row6 = $row['AVG(fb26)'] + $row['AVG(fb27)'] + $row['AVG(fb28)'] + $row['AVG(fb29)'] + $row['AVG(fb30)']; $row7 = $row['AVG(fb30)'] + $row['AVG(fb32)'] + $row['AVG(fb33)'] + $row['AVG(fb34)'] + $row['AVG(fb35)']; $row8 = $row['AVG(fb36)'] + $row['AVG(fb37)'] + $row['AVG(fb38)'] + $row['AVG(fb39)'] + $row['AVG(fb40)']; $row9 = $row['AVG(fb40)'] + $row['AVG(fb42)'] + $row['AVG(fb43)'] + $row['AVG(fb44)'] + $row['AVG(fb45)']; $row10 = $row['AVG(fb46)'] + $row['AVG(fb47)'] + $row['AVG(fb48)'] + $row['AVG(fb49)'] + $row['AVG(fb50)']; $row1Avg = $row1 / 5; $row2Avg = $row2 / 5; $row3Avg = $row3 / 5; $row4Avg = $row4 / 5; $row5Avg = $row5 / 5; $row6Avg = $row6 / 5; $row7Avg = $row7 / 5; $row8Avg = $row8 / 5; $row9Avg = $row9 / 5; $row10Avg = $row10 / 5; echo " all of those"; </code></pre> <p>p.s. As I've done everything without using this PDO syntax everyone is talking about, I would really appreciate any help apart from PDO solutions unless it's not possible.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload