更新第一行mysql php [英] Update the first row mysql php

查看:70
本文介绍了更新第一行mysql php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新数据库中的第一行.我使用Limit 1仅更新第一行,但没有任何反应.肯定有匹配的行,但数据库中没有任何变化.

I'm trying to update my first row in my database. I use the Limit 1 to only update the first row but nothing is happening. There are definitely matching rows but nothing changes in the database.

这是代码:

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进行比较.

In MySQL use IS NULL to compare with NULL.

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

这篇关于更新第一行mysql php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆