php - 更新第一行mysql php

标签 php mysql sql

我正在尝试更新数据库中的第一行。我使用 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 NULLNULL 进行比较。

例如:“UPDATE table SET field = 'yes' WHERE field IS NULL

关于php - 更新第一行mysql php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21008188/

相关文章:

Mysql计算总分钟数

c# - 将大量 SQL 结果返回到 C# 数组

SQLFiddle:必须声明标量变量错误

MySQL 更新行的过程

php - ob_clean() 清除所有级别的ob?

php - 获取我的表单数据以发布到 mysql 数据库

php - 自动从表中选择随机行

javascript - 对图像使用分页

php - 使用 MySQL 搜索文本

mysql - 需要调整哪些设置来改进包含大量列和少量联接的 SELECT?