代码逻辑不计算正确的数据

时间:2011-03-06 19:08:24

标签: php mysql

我非常希望有人可以帮我解决这个错误。不可否认,我是一个新手,我已经尝试了60多个小时来解决这个问题,但我无法实现这一目标。

是的,到此为止。

我有一支由20支球队组成的足球联赛。它有效,很棒,很快乐。但是,我需要将它减少到12支球队。一个问题,因为我没有创建网站,其他人做了一段时间。

所以我需要修改一个20到12的表。这就是全部。

闹钟,我翻了个袖子,仔细检查了代码并找到了这个位置;

<?php 

$query = $SITE -> Query ( 'SELECT a.*, b.name, b.colour, b.txtcolour, 
(sum((a.wins*3) + (a.draws*1) - a.pts)) as points, 
(sum(a.wins + a.losses + a.draws)) as pld, 
(sum(a.glsfor - a.glsaga)) as gd 
FROM got_standings a 
inner join got_clubs b on (a.cid = b.id) 
WHERE a.season = "'.$url[2].'" 
GROUP BY a.cid 
ORDER BY points DESC, gd DESC, glsfor DESC' ); 

if ($SITE -> Count ($query) == 0) { 
$loop = 0; 

while($loop <= 19) { 
++$loop; 
?> 

在我试图解决的60个小时内经过一些试验和错误之后,我改变了;

while($ loop&lt; = 19)

要;

while($ loop&lt; = 11)

而且很低,看来,系统现在促使我进入一个联赛表中的12支队伍,反对20。精湛。或者我认为......

当我第一次将数据输入表格并“提交”时,它可以正常工作 - 因为它在上述变更之前列出的20个团队时完美无缺。但是,当我'更新'/对联赛表进行任何不断的更改时,它也会计算之前的

所以对于'塔尔伯特港镇',我进入“1胜”,“1平局”,“1失利”,“5个进球得分”,“5个进球让步” 它有效。它计算了3场比赛和4场比赛(胜利3场,平局1场,失利0场)as shown here

但是,当我输入其他信息时,为“Aberystwyth Town”和“更新”输入相同的信息,会再次计算以前数据(塔尔伯特港镇)的信息吗?as shown here

我完全失去了。对于任何帮助,我都会非常感激和感激。

整个代码粘贴在底部。

请大家!帮助一个白痴! 8)

<?php   
} 
} else if ($url[3] == 'league') { 
if ($url[4] == 'standings') { 
?> 
<ul class="buttonbar"> 
<li class="button"><a href="<?=$CONF['site']; ?>sitecontrol/fixtures/<?=$url[2]; ?>/add/league">Add Fixture</a></li> 
<li class="button"><a href="<?=$CONF['site']; ?>sitecontrol/fixtures/<?=$url[2]; ?>/league/standings">Standings</a></li> 
</ul> 
<form action="<?=$CONF['site']; ?>mcms/applications/fixtures/submit.php?do=fixtures&amp;action=standings&amp;season=<?=$url 

[2]; ?>&amp;comp=<?=$url[3]; ?>" method="post" name="standings"> 
<div class="table"> 
<div class="th">Welsh Premier League Standings</div> 
<ul class="tr shadow"> 
<li class="td-squadno">Pos.</li> 
<li class="td4" style="width: 170px;">Team</li> 
<li class="td4">PLD</li> 
<li class="td4">W</li> 
<li class="td4">D</li> 
<li class="td4">L</li> 
<li class="td4">+</li> 
<li class="td4">-</li> 
<li class="td4">PTS</li> 
</ul> 
<?php 

$query = $SITE -> Query ( 'SELECT a.*, b.name, b.colour, b.txtcolour, 
(sum((a.wins*3) + (a.draws*1) - a.pts)) as points, 
(sum(a.wins + a.losses + a.draws)) as pld, 
(sum(a.glsfor - a.glsaga)) as gd 
FROM got_standings a 
inner join got_clubs b on (a.cid = b.id) 
WHERE a.season = "'.$url[2].'" 
GROUP BY a.cid 
ORDER BY points DESC, gd DESC, glsfor DESC' ); 

if ($SITE -> Count ($query) == 0) { 
$loop = 0; 

while($loop <= 11) { 
++$loop; 
?> 
<ul class="tr" id="team_<?=$loop; ?>"> 
<li class="td-squadno"><?=$loop; ?></li> 
<li class="td2" style="width: 170px;"> 
<?php 

echo ( ' 
<select name="cid[]"> 
' ); 

$sql = $SITE -> Query ( 'SELECT id, name FROM got_clubs WHERE country = "Wales" ORDER BY name ASC' ); 

while($club = $SITE -> FetchArray($sql)) { 
echo ( '<option value="'.$club['id'].'"' ); 
if ($club['id'] == '1') echo ( ' SELECTED' ); 
echo ( '>'.$club['name'].'</option>' ); 
} 

echo ( ' 
</select> 
' ); 

?> 
</li> 
<li class="td4"></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=wins[]]').val(parseInt($('ul#team_<? 

=$loop; ?> li.td4 input[name=wins[]]').val())+1); return false;">+</a> <input type="text" name="wins[]" value="0" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=draws[]]').val(parseInt($('ul#team_<? 

=$loop; ?> li.td4 input[name=draws[]]').val())+1); return false;">+</a> <input type="text" name="draws[]" value="0" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=losses[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=losses[]]').val())+1); return false;">+</a> <input type="text" name="losses[]" 

value="0" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=glsfor[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=glsfor[]]').val())+1); return false;">+</a> <input type="text" name="glsfor[]" 

value="0" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=glsaga[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=glsaga[]]').val())+1); return false;">+</a> <input type="text" name="glsaga[]" 

value="0" /></li> 
<li class="td4">- <input type="text" name="pts[]" /></li> 
</ul> 
<?php 
} 
} else { 
$loop = 0; 

while($row = $SITE -> FetchArray($query)) { 
++$loop; 
?> 
<ul class="tr" id="team_<?=$loop; ?>"> 
<li class="td-squadno"><?=$loop; ?></li> 
<li class="td-club" style="width: 160px; margin-left: 10px; background-color: #<?=$row['colour']; ?>; color: #<? 

=$row['txtcolour']; ?>;"><?=$row['name']; ?><input type="hidden" name="cid[]" value="<?=$row['cid']; ?>" /></li> 
<li class="td4"><?=$row['pld']; ?></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=wins[]]').val(parseInt($('ul#team_<? 

=$loop; ?> li.td4 input[name=wins[]]').val())+1); return false;">+</a> <input type="text" name="wins[]" value="<?=$row 

['wins']; ?>" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=draws[]]').val(parseInt($('ul#team_<? 

=$loop; ?> li.td4 input[name=draws[]]').val())+1); return false;">+</a> <input type="text" name="draws[]" value="<?=$row 

['draws']; ?>" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=losses[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=losses[]]').val())+1); return false;">+</a> <input type="text" name="losses[]" 

value="<?=$row['losses']; ?>" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=glsfor[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=glsfor[]]').val())+1); return false;">+</a> <input type="text" name="glsfor[]" 

value="<?=$row['glsfor']; ?>" /></li> 
<li class="td4"><a href="#" onclick="$('ul#team_<?=$loop; ?> li.td4 input[name=glsaga[]]').val(parseInt 

($('ul#team_<?=$loop; ?> li.td4 input[name=glsaga[]]').val())+1); return false;">+</a> <input type="text" name="glsaga[]" 

value="<?=$row['glsaga']; ?>" /></li> 
<li class="td4"><?=$row['points']; ?> (- <input type="text" name="pts[]" value="<?=$row['pts']; ?>" />)</li> 
</ul> 
<?php 
} 
} 

?> 
<div class="tf"><input type="submit" value="Update Standings" /> or <a href="<?=$CONF['site']; ?>sitecontrol/fixtures/<? 

=$url[2].'/'.$url[3]; ?>">Cancel</a></div> 
</div> 
</form> 
<p>Do not use the points column for anything other than points deductions. If a points deduction is carried out by the 

Premier League, use the input box to enter how many points have been taken away, e.g. Portsmouth in 2009/10 would have 

&quot;9&quot; in their points input box.</p> 
<p>Matches played and points columns will update automatically. The position of each team in the league table will also be 

automatically updated.</p> 
<?php 
} else { 
?> 
<ul class="buttonbar"> 
<li class="button"><a href="<?=$CONF['site']; ?>sitecontrol/fixtures/<?=$url[2]; ?>/add/league">Add Fixture</a></li> 
<li class="button"><a href="<?=$CONF['site']; ?>sitecontrol/fixtures/<?=$url[2]; ?>/league/standings">Standings</a></li> 
</ul> 
<div class="table"> 
<div class="th">Premier League Fixtures</div> 
<?php 
$query = $SITE -> Query ( ' 
SELECT a.id, a.rid, home, away, homescore, awayscore, date, b.name as hometeam, c.name as awayteam FROM 

got_fixtures a 
inner join got_clubs b on (a.home = b.id) 
inner join got_clubs c on (a.away = c.id) 
WHERE a.cid="1" AND a.season = "'.$url[2].'" AND (a.home = "1" OR a.away = "1") 
ORDER BY date ASC' ); 

while($row = $SITE -> FetchArray($query)) { 
?> 
<ul class="tr"> 
<li class="td-squadno"><?=$row['rid']; ?></li> 
<li class="td-home"><?=$row['hometeam']; ?></li> 
<li class="td-score"><?=$row['homescore']; ?> - <?=$row['awayscore']; ?></li> 
<li class="td-away"><?=$row['awayteam']; ?></li> 
<li class="td-kickoff"><?=date('D. jS F y, H:i', $row['date']); ?></li> 
<li class="td-end"><a href="<?=$CONF['site']?>sitecontrol/fixtures/<?=$url[2]; ?>/edit/<?=$url[3]; ?>/<?=$row['id']; 

?>">Edit</a> or <a href="<?=$CONF['site']; ?>mcms/applications/fixtures/submit.php?do=fixtures&amp;action=delete&amp;id=<? 

=$row['id']; ?>&amp;comp=<?=$url[3]; ?>&amp;season=<?=$url[2]; ?>">Remove</a></li> 
</ul> 
<?php   
} 
?> 
<div class="tf"></div> 
</div>

1 个答案:

答案 0 :(得分:0)

听起来好像没有将它正确插入数据库。查找包含INSERT或UPDATE的SQL查询。

上面代码中的SQL显示数据库中的数据,而不是添加到数据库中。你的问题将在其他地方。由于从数据库中提取的while循环使用值19进行硬编码,因此更新代码可能也是如此。

还要登录您的主机帐户,转到PhpMyAdmin,然后查看数据库本身。看看如何设置。