在PHP中,是否有一种方法可以使用以下语句来检查行是否存在?
如果“表格案例中有一个”乘客“字段,其值为4 WHERE case
='$ case'{
码...
}
答案 0 :(得分:4)
$query ='SELECT 1 FROM cases WHERE passenger = 4 AND case ="$case"';
$result = mysql_query($query);
if(mysql_num_rows($result)){
//exists
}
答案 1 :(得分:0)
不那么优雅,没有。但是您可以运行查询然后比较结果:
$case = mysql_real_escape_string($case); // make sure to escape values going in queries
if (($r = mysql_query("SELECT * FROM cases WHERE passenger=4 AND case='{$case}'")) !== false)
{
if (mysql_num_rows($r))
{
// your code here.
}
}