1

我的 SQL 有问题。例如,我有链接http://www.site.com/single_video.php?id=96&kategorija=fails

在该页面中有两列,一列用于显示该视频,另一列用于相关视频。但是如果用户在链接中添加 ',它将在“相关视频”列中不显示任何内容。所以我试图过滤掉“有效” “类别..但不知何故它不起作用..这是我的代码......

<?php
include 'includes/connect_video_index.php';
mysql_query("SET NAMES utf8"); //recimo bazi da postoje čak i hrvatska slova :D 
$result1 = mysql_query('SELECT * 
                          FROM video 
                         WHERE id!="'.$id1.'" 
                           AND kategorija="'.$escaped_cat.'" 
                      ORDER BY RAND() 
                         LIMIT 10', $con1);
while ($row1 = mysql_fetch_array($result1)){
    $kat = $_GET['kategorija'];
    $kategorija = mysql_real_escape_string($kat);
    if ($kategorija == $row1['kategorija']){
        echo 'This category exists'; //this part is working
    } else {
        //this part doesn't works when I enter blah blah, or whatever :S
        echo "This category doesnt' exist"; 
    }
}
4

1 回答 1

0

如果您键入“somethingThatCantBeFound”,则找不到任何行,并且 while 循环进行... 0 次迭代。这意味着您无法到达 if 语句。如果$escaped_cat$kategorija相同,我的意思是。他们是吗?

如果您想知道某个类别是否存在视频,您可以这样做:

SELECT EXISTS (SELECT * FROM video WHERE kategorija = 'some category')
于 2013-07-20T11:23:29.523 回答