如果mysql_num_rows返回0结果时无法识别语句 [英] If statement not recognising when mysql_num_rows returns 0 results
问题描述
我正在尝试运行代码,似乎给了我错误的结果,我尝试了很多方法,但仍然没有得到.在这里:
I am trying to run the code and it seems to be given me wrong result, I tried many ways and still not getting it. Here it is:
//compares vid num to db been result
$id = mysql_real_escape_string(@$_GET['g']);
$vid = mysql_real_escape_string(@$_GET['v']);
$sql= mysql_query("SELECT videos.* FROM videos WHERE videos.email =
(SELECT email FROM page WHERE page.user_id = '$id')
AND videos.videoid = '$vid'");
if (mysql_num_rows($sql) == 0) { echo "none";} else echo "it exists";
如果我在phpmyadmin中运行查询,它将运行正确,但是在PHP中运行时,结果是offfff,即使phpmyadmin返回0(正确),它也会不断回显它的存在.我一直试图弄清楚这一点,却一无所获.我尝试了!isset($sql)
相反的东西.
If I run the query in phpmyadmin it runs correct, but when run in PHP the result is offfff, it keeps echoing it exists even when phpmyadmin returns 0 which is correct. I have been trying to figure this out and keeps getting nothing. I have tried !isset($sql)
oppositely the something.
推荐答案
if ( $sql ) // valid result
{
if ( mysql_num_rows( $sql ) > 0 ) // more than 0 records
echo "it exists";
else
echo "none";
}
如果上面的代码仍然给您带来问题,则您的mysql查询中的某些内容导致找到结果.
If the above code still gives you a problem, then something in your mysql query is causing a result to be found.
这篇关于如果mysql_num_rows返回0结果时无法识别语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!