Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL & PHP Sum of rows in foreach
    primarykey
    data
    text
    <p>Im trying to get the sum of workouts in a row and then order all rows by the sums to get what place the team is in and so there listed in the correct order. Im getting a little lost in my own logic right now trying to figure this out. I understand the MYSQL sum function but cant seem to see how i could use it to help me in this instance.</p> <p>So something like this: <img src="https://i.stack.imgur.com/TjBlc.png" alt="Example"></p> <p>Here is my current Table schema:</p> <pre><code>CREATE TABLE workouts ( team_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, username VarChar(255) NOT NULL, team_name VarChar(50) NOT NULL, week1 INT NOT NULL, week2 INT NOT NULL, week3 INT NOT NULL, week4 INT NOT NULL, week5 INT NOT NULL, week6 INT NOT NULL, week7 INT NOT NULL, week8 INT NOT NULL, week9 INT NOT NULL, week10 INT NOT NULL, week11 INT NOT NULL, week12 INT NOT NULL ) engine=innodb; </code></pre> <p>And Here is my display so far:</p> <pre><code>&lt;?php $count = 0; $statement = $db-&gt;query('SELECT * FROM workouts'); foreach($statement as $row): ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php $count++; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['team_name']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week1']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week2']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week3']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week4']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week5']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week6']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week7']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week8']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week9']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week10']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week11']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php $row['week12']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; ?&gt; </code></pre>
    singulars
    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