我正在尝试更新数据库中的第一行。我使用 Limit 1
仅更新第一行但没有任何反应。肯定有匹配的行,但数据库中没有任何变化。
代码如下:
foreach ($player_fromsite as $match_player_in_game) {
//$querytwo = 'INSERT INTO `'.$tablename.'` '.' (`'.$match_player_in_game.'`) '.'VALUES'.'("' . 'yes' . '")';
$querytwo = 'UPDATE '.$tablename.' SET `'.$match_player_in_game.'` = "'.'yes'.'" WHERE `'.$match_player_in_game.'` = "'.'NULL'.'" LIMIT 1';
$querythree = 'UPDATE '.$tablename.' SET `'.$match_player_in_game.'` = "'.'yes'.'" WHERE `'.$match_player_in_game.'` = "'.'NULL'.'" LIMIT 1';
for($a=0;$a<11;$a++){
if($match_player_in_game == $home_players[$a]){
// Insert a row of information into the table "example"
mysql_query($querytwo) or die(mysql_error());
}else{
mysql_query($querythree) or die(mysql_error());
}
}
}
查询是否正确?
最佳答案
在 MySQL 中使用 IS NULL
与 NULL
进行比较。
例如:“UPDATE table SET field = 'yes' WHERE field IS NULL
”
关于php - 更新第一行mysql php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21008188/