查询在搜索php中是空的

时间:2013-03-02 17:50:45

标签: php mysql

我尝试使用选择选项进行此搜索,以选择哪个网站或所有网站。 当我点击所有网站时,它的工作原理。当我点击“4shared”时,它有效。但是,当我点击“putlocker”时,我得到了这个。查询是空的。

我真的不知道我做错了什么

<?php 
include"inc/connect.php"; 
include"inc/functions.php";
error_reporting(0);
if(isset($_GET['s']) && $_GET['s'] != ""){
    $s = $_GET['s'];
    $w = $_GET['w'];

    if($w == 'all'){
        $sql = "SELECT * FROM result WHERE (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
    }else if($w == 'Sockshare'){
        $sql = "SELECT * FROM result WHERE website='Sockshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
    }else if($w == 'Putlocker'){
        $sql == "SELECT * FROM result WHERE website='Putlocker' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
    }else if($w == '4shared'){
        $sql = "SELECT * FROM result WHERE website='4shared' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
    }else if($w == 'Rapidshare'){
        $sql = "SELECT * FROM result WHERE website='Rapidshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
    }

    $query = mysql_query($sql) or die(mysql_error());

    $count = mysql_num_rows($query);

    if($count > 1){
        while($row = mysql_fetch_array($query)){
            $name = $row["name"];
            $details = $row["details"];
            $url = $row["url"];

            $results .= '
            <div id="stitle">' .$name. '</div>
            <div id="details">' .$details. '</div>
            <div id="url"><a target="_blank" href="' .$url. '">' .$url. '</a></div>';
        }
        } else {
            $results = 'Nothing found!';
        }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Findrfile.com - Putlocker Search | Sockshare search | Mediafire Search</title>
<link href='http://fonts.googleapis.com/css?family=Orienta' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="main.css" />
</head>

<body>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<?php include"header.php"; ?>
<div id="spacer"></div>
<?php include"litsearch.php"; ?>
<div id="nuresults"><span class="blue"><?php echo $count; ?> Results found</span></div>
<div id="spacerx"></div>
<div id="wrapper">
<div id="spacerx"></div>
<div id="content">
<?php echo $results; ?>
<div class="clear"></div>

</div>
<div id="spacerx"></div>
<div id="spacer"></div>
</div>
<?php include"footer.php"; ?>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

$sql == "SELECT * FROM result WHERE website='Putlocker' AND (name LIKE '%".$s."%') OR (keyword LIKE '%".$s."%')";注意到==,这是一个比较运算符,因此它不会将值设置为$sql 我想这可能是你的问题。

答案 1 :(得分:0)

更改

while($row = mysql_fetch_array($query)){

while($row = mysql_fetch_assoc($query)){

因为你使用了关联数组。

        $name = $row["name"];
        $details = $row["details"];
        $url = $row["url"];

如果你想使用

while($row = mysql_fetch_array($query)){

像:

    $name = $row[0];
    $details = $row[1];
    $url = $row[2];

我错了吗?

ALSO:

你检查是否设置了$ _GET [“s”]但你没有检查$ _GET [“w”]