doo6568 2012-10-22 19:37
浏览 60

PHP - 在填写表单i $后尝试为多个玩家执行SQL代码循环

Trying to do a loop in SQL code for multiple players after filling form i$.

Can't seem to find the answer online. THANK YOU for any help you can provide me.

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}    
mysql_select_db("mbbcom1_rfhl", $con);

for ($i=1; $i<=6; $i++)
{       
    $sql="UPDATE `mbbcom1_rfhl`.`_statbu`
        SET gp= gp + '$_POST[gp$i]', g= g + '$_POST[g$i]', a= a + '$_POST[a$i]', shot=    shot + '$_POST[s$i]', pm= pm + '$_POST[pm$i]', ppg= ppg + '$_POST[ppg$i]', shg= shg + '$_POST[shg$i]', bs= bs + '$_POST[blk$i]', gwg= gwg + '$_POST[gwg$i]', sog= sog + '$_POST[sog$i]', soa= soa + '$_POST[soa$i]', pim= pim + '$_POST[pim$i]' WHERE `season` =9 AND `_statbu`.`player_id` = $i ORDER BY `_statbu`.`player_id` ASC";
}

if (!mysql_query($sql,$con))
{
    die('Error: ' . mysql_error());
}
mysql_close($con)
?> 
  • 写回答

3条回答 默认 最新

  • douyue3800 2012-10-22 19:42
    关注

    When you add some decent indenting to your code, it becomes clear that you are running the query outside of the for loop so it can only run the last update.

    评论

报告相同问题?