简体   繁体   中英

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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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