开发者

If mysql_num_rows is greater than 0

I'm trying to get this statement to work... I'm checking to see if $batchid exist and if it does then stop process the script.

开发者_高级运维if (mysql_num_rows(mysql_query("select batch_id from load_test 
                    where batch_id='".$batchid."'")) > 0) {
    die("Error batch already present");
}


First, make sure that $batchid is escaped with mysql_real_escape_string.

This code should work (non case-sensitive):

if (mysql_result(mysql_query("SELECT COUNT(*) FROM load_test WHERE batch_id='".$batchid."'"), 0) > 0) {
    die("Error batch already present");
}

The case-sensitive version (source):

if (mysql_result(mysql_query("SELECT COUNT(*) FROM load_test WHERE batch_id LIKE BINARY '".$batchid."'"), 0) > 0) {
    die("Error batch already present");
}


Simply write :

$res=mysql_query("select count(*) from load_test where batch_id='".$batchid."'");
if($res>0)
{
           die("Error batch already present");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜