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";
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";
}
If the above code still gives you a problem, then something in your mysql query is causing a result to be found.
this works, thank you guys for your help
$vid = mysql_real_escape_string(@$_GET['kjvid']);
$id = mysql_real_escape_string(@$_GET['pid']);
$kjvid = mysql_query("SELECT videos.*, page.email FROM videos LEFT JOIN page ON page.email = videos.email WHERE page.user_id = '$id' AND videos.videoid = '$vid'");
if (mysql_num_rows($kjvid) == 0) { echo "none";} else echo "it exists";
精彩评论