Note that there are some explanatory texts on larger screens.

plurals
  1. PODifference between array values
    text
    copied!<p>Update</p> <p>With this code I can retrieve the difference, but I can see only the first athlete of the query. Why? Shouldn't the while loop for x times, where x is the number of results?</p> <pre><code>function difference() { global $db; $result = $db-&gt;query(" SELECT * FROM maxithlon WHERE owner = '". $_SESSION[teamid] ."' AND season = '". $this-&gt;season ."' AND week = '". $this-&gt;currentWeek ."' ORDER BY RAND(); "); while ($row = $result-&gt;fetch_assoc()) { $result2 = $db-&gt;query(" SELECT * FROM maxithlon WHERE owner = '". $_SESSION[teamid] ."' AND season = '". $this-&gt;season ."' AND week = '". $this-&gt;currentWeek ."-1' AND athleteId = '". $row[athleteId] ."' "); while ($row2 = $result2-&gt;fetch_assoc()) { $difference[$row2[athleteId]][form] = $row[form] - $row2[form]; $difference[$row2[athleteId]][maxid] = $row[maxid] - $row2[maxid]; $difference[experience] = $row[experience] - $row2[experience]; $difference[mood] = $row[mood] - $row2[mood]; $difference[strenght] = $row[strenght] - $row2[strenght]; $difference[stamina] = $row[stamina] - $row2[stamina]; $difference[speed] = $row[speed] - $row2[speed]; $difference[agility] = $row[agility] - $row2[agility]; $difference[jump] = $row[jump] - $row2[jump]; $difference[throws] = $row[throws] - $row2[throws]; $difference[specialty1] = $row[specialty1] - $row2[specialty1]; $difference[specialty2] = $row[specialty2] - $row2[specialty2]; $difference[height] = $row[height] - $row2[height]; $difference[weight] = $row[weight] - $row2[weight]; $difference[fans] = $row[fans] - $row2[fans]; $difference[wage] = $row[wage] - $row2[wage]; return($difference); } } } </code></pre> <p>I've searched for an answer that could satisfy my needings, but I couldn't find it.</p> <p>I have a database, with the "maxithlon" table that contains the athletes' data. The two functions are defined to retrieve the athletes' data and to put them in a array. The first retrieves the data of the last week, the second the data of the current one.</p> <p>I need to compare the two arrays to obtain the difference between the values of the two weeks. Do you see a possible solution?</p>
 

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