dongsi0625 2011-03-06 19:08
浏览 57
已采纳

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

I'm desperately hoping someone can assist me with this error. Admittedly, I'm a novice and I've tried for literally 60+ hours to fix this but I just can't get there.

Right, here goes.

I have a football league table of 20 teams. It works, it's great, happy days. However, I needed to reduce it to 12 teams. A problem because I didn't create the website, someone else did a while back.

So I've needed to amend a table with 20, to 12. That's all.

Daunted, I rolled up my sleeves scoured the code and located this bit;

<?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; 
?> 

After some trial and error in those 60 hours I've been trying to resolve, I changed;

while($loop <= 19)

to;

while($loop <= 11)

And low and behold, the system now prompted me to enter 12 teams into a league table, as oppose to 20. Superb. Or so I thought...

When I first enter the data into the table and 'submit', it works - as it did perfectly when 20 teams where listed before the above change. However, when I 'update'/make any continual changes to the league table, it also calculates the previous

So for 'Port Talbot Town' I enter "1 Win", "1 Draw", "1 Loss", "5 Goals Scored" "5 Goals Conceded" And it works. It calculates 3 games played and 4 points (3 for a win, 1 for a draw, 0 for a loss)as shown here.

BUT, when I then enter other information, so entering the same information for 'Aberystwyth Town'and 'update', the information for the previous data (Port Talbot Town) is calculated again?as shown here.

I'm at complete loss. I'd be incredibly grateful and appreciative for any assistance.

The entire code is pasted at the bottom of this.

Please guys! Help an idiot out! 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条回答 默认 最新

  • dougou6213 2011-03-06 19:30
    关注

    Sounds like it's not inserting it correctly into the database. Look for a SQL query that has INSERT or UPDATE in it.

    The SQL in the code above is displaying data from the database, not adding to it. Your problem will be elsewhere. As the while loop pulling from the database was hard coded with the value 19, then the update code will probably be as well.

    Also login to your hosting account, go to PhpMyAdmin, and have a look at the database itself. See how that is set up.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决