简体   繁体   English

PHP Mysql如果行为空则删除

[英]PHP Mysql DELETE if row was empty

I have this 4 fields on my table. 我的桌子上有这4个字段。 p1 p2 p3 p4 gameID is the row table. p1 p2 p3 p4 gameID是行表。 So only that row should be deleted. 因此,仅应删除该行。 So when it update the playe1 = '' it will delete the row table. 因此,当更新playe1 = '' ,它将删除行表。

Note that it will delete only if the p1 p2 p3 p4 is empty. 注意,只有在p1 p2 p3 p4为空时,它才会删除。

Is my code if else correct? 我的代码是否正确? it update the row player1 to empty but it did not delete. 它将行player1更新为空,但没有删除。

if($p1 == $email_val){
    $sql_update_player = mysql_query("UPDATE game SET player1='' WHERE gameID='$gameID' ") or die ( mysql_error() );
$stat = "1";
    if(empty($p1) and empty($p2) and empty($p3) and empty($p4) ){
        $sqlDelGame = mysql_query("DELETE FROM game WHERE gameID='$gameID'") or die ( mysql_error() );
        echo "Game deleted";
    }
}

if you want to delete games that dosn't have any players yet, you can run: 如果要删除尚无任何玩家的游戏,可以运行:

DELETE FROM game
WHERE player1 = ''
  AND player2 = ''
  AND player3 = ''
  AND player4 = '';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM