-1

I am working on a simple gaming ladder script. I am having little to no luck trying to find an effective way to reset my ladder information while leaving my table id and name fields intact.

I am trying to get create a loop to update my entire table, similar to the way I draw my table. Shown below.

......
//Start displaying ladder with with team with most wins at the top
echo "<TABLE border=1 width=500 align=center><TR>";

foreach($db->query('SELECT * FROM test ORDER BY win DESC , name ASC') as $row) {
    echo "<TR><TD>" . $row['name'] . "</TD><TD>" . $row['win'] . "</TD><TD>";
    echo $row['loss'] . "</TD><TD>" . $row['battles'] . "</TD><TD>";
    echo $row['score'] . "</TD></TR>"; 
}
......

I currently have a table with 6 fields(id,name,win,loss,battles,score). I want to reset the values of win,loss,battles, and score back to 0. While leaving id and name alone. Effective reseting my ladder for a new season to begin.

The only way I have been able to complete this is to find out how many rows there are and run a for loop. It seems vary inefficient. Was hoping I could get some better insight as to how to go about this.

4

2 回答 2

0
UPDATE 'test' SET 'win'=0, 'loss'  =0,'battles' =0,'score'  = 0;

... 不?

于 2013-11-09T12:23:52.283 回答
-1

删除列并重新创建它们。

ALTER TABLE 'test' DROP 'win';
ALTER TABLE 'test' DROP 'loss';
ALTER TABLE 'test' DROP 'battles';
ALTER TABLE 'test' DROP 'score';
ALTER TABLE 'test' ADD COLUMN 'win'     INT DEFAULT 0;
ALTER TABLE 'test' ADD COLUMN 'loss'    INT DEFAULT 0;
ALTER TABLE 'test' ADD COLUMN 'battles' INT DEFAULT 0;
ALTER TABLE 'test' ADD COLUMN 'score'   INT DEFAULT 0;
于 2013-11-09T09:49:58.643 回答