有問題。只是找不到問題。我有兩張牌第一張牌:hold1,hold2,hold1goal,hold2goal和另一個hold:hold,fgoal,agol。我試圖讓所有hold1goal和hold2goal在保持表中的fgoal和agoal。我相當新的SQL。foreach循環中的更新表
<?php
include "config.php";
foreach($db->query('SELECT * FROM kampe') as $row){
$fgoal = $row['hold1goal'];
$agoal = $row['hold2goal'];
$hold = $row['hold1'];
$stmt = $db->prepare("UPDATE hold SET fgoal = :fgoal, agoal = :agoal WHERE hold = :hold");
$stmt->bindParam(':fgoal', $fgoal);
$stmt->bindParam(':agoal', $agoal);
$stmt->bindParam(':hold', $hold);
$stmt->execute();
/* print $agoal . "\n";
$fgoal = $row['hold2goal'];
$agoal = $row['hold1goal'];
$hold = $row['hold2'];
$stmt = $db->prepare("UPDATE hold SET fgoal = :fgoal, agoal = :agoal WHERE hold = :hold");
$stmt->bindParam(':fgoal', $fgoal);
$stmt->bindParam(':agoal', $agoal);
$stmt->bindParam(':hold', $hold);
$stmt->execute(); */
}
?>
這是結果。只有'Odensevej'發生了變化。認爲foreach循環會改變所有。
申佩
INSERT INTO `kampe` (`kampID`, `hold1`, `hold2`, `hold1goal`, `hold2goal`) VALUES
(1, 'marksvej', 'holdet', 0, 0),
(2, 'tervej', 'dfdf', 0, 0),
(3, 'Odensevej', 'holdet2', 2, 1),
(4, 'hest', 'hestener', 0, 0),
(5, 'holdet', 'tervej', 0, 0),
(6, 'dfdf', 'marksvej', 2, 6),
(7, 'Odensevej', 'hest', 0, 0),
(8, 'hestener', 'holdet2', 3, 1),
(9, 'dfdf', 'holdet', 0, 0),
(10, 'tervej', 'marksvej', 0, 0),
(11, 'hestener', 'Odensevej', 2, 1),
(12, 'holdet2', 'hest', 0, 0),
(13, 'Odensevej', 'holdet', 0, 0),
(14, 'dfdf', 'holdet2', 0, 0),
(15, 'hest', 'tervej', 2, 3),
(16, 'hestener', 'marksvej', 0, 0),
(17, 'holdet2', 'holdet', 0, 0),
(18, 'Odensevej', 'marksvej', 0, 0),
(19, 'hest', 'dfdf', 0, 0),
(20, 'tervej', 'hestener', 0, 0),
(21, 'hest', 'holdet', 0, 0),
(22, 'marksvej', 'holdet2', 0, 0),
(23, 'tervej', 'Odensevej', 0, 0),
(24, 'dfdf', 'hestener', 0, 0),
(25, 'holdet', 'hestener', 0, 0),
(26, 'hest', 'marksvej', 0, 0),
(27, 'tervej', 'holdet2', 0, 0),
(28, 'Odensevej', 'dfdf', 3, 2);
HOLD
INSERT INTO `hold` (`id`, `hold`, `leder`, `telefon`, `email`, `fgoal`, `agoal`, `p`) VALUES
(6, 'holdet', 'kim anov', '345345', '[email protected]', 0, 0, 0),
(20, 'marksvej', 'svend dellepude', '345345', '[email protected]', 0, 0, 1),
(61, 'tervej', 'Kim Test', '34343434', '[email protected]', 0, 0, 1),
(64, 'dfdf', 'dfdf', 'dfdf', '[email protected]', 0, 0, 0),
(67, 'Odensevej', 'Brian Anov', '34343434', '[email protected]', 3, 2, 2),
(69, 'holdet2', 'asda asdasd', '4234234', '[email protected]', 0, 0, 0),
(70, 'hest', 'kim a', '323423', '[email protected]', 0, 0, 0),
(71, 'hestener', 'asdasd asdasd', '3423423423', 'safsdfasdasd.com', 0, 0, 2);
問題是什麼? :? – KingCrunch 2014-10-29 14:10:11
**如何**這不適合你? – 2014-10-29 14:10:49
它只從kampe最後一行插入數據來保存。不明白爲什麼它不循環,並將所有值插入不同的保留。 – 2014-10-29 14:17:21