if 语句无法识别 mysql_num_rows 返回 0 结果时

发布于 2024-11-19 04:15:25 字数 588 浏览 0 评论 0原文

我正在尝试运行代码,但似乎给了我错误的结果,我尝试了很多方法但仍然没有得到它。这里是:

//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 中运行时,结果是 offffff,即使 phpmyadmin 返回正确的 0,它也会不断回显它的存在。我一直试图弄清楚这一点,但一无所获。我尝试过相反的方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难忘№最初的完美 2024-11-26 04:15:25
if ( $sql ) // valid result
{
    if ( mysql_num_rows( $sql ) > 0 ) // more than 0 records
        echo "it exists";
    else
        echo "none";
}

如果上面的代码仍然给您带来问题,那么您的 mysql 查询中的某些内容导致找不到结果。

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.

杯别 2024-11-26 04:15:25

这有效,谢谢你们的帮助

$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";

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文