更新
使用此代码,我可以检索差异,但我只能看到查询的第一个运动员。为什么?while 不应该循环 x 次,其中 x 是结果数?
function difference() {
global $db;
$result = $db->query("
SELECT *
FROM maxithlon
WHERE owner = '". $_SESSION[teamid] ."'
AND season = '". $this->season ."'
AND week = '". $this->currentWeek ."'
ORDER BY RAND();
");
while ($row = $result->fetch_assoc()) {
$result2 = $db->query("
SELECT *
FROM maxithlon
WHERE owner = '". $_SESSION[teamid] ."'
AND season = '". $this->season ."'
AND week = '". $this->currentWeek ."-1'
AND athleteId = '". $row[athleteId] ."'
");
while ($row2 = $result2->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);
}
}
}
我一直在寻找一个可以满足我需求的答案,但我找不到它。
我有一个数据库,其中包含运动员数据的“maxithlon”表。这两个函数被定义为检索运动员的数据并将它们放入一个数组中。第一个检索上周的数据,第二个检索当前一周的数据。
我需要比较两个数组以获得两周的值之间的差异。你看到一个可能的解决方案吗?