mysql_num_rows()期望参数1是资源,布尔值是给定的

时间:2014-07-16 08:32:43

标签: php mysql

1.这是我的代码         搜索WHERE 1";

    foreach ($terms as $each){
    $i++;

    if ($i == 0)
        $query .= "keywords LIKE '%$each%' "; 
    else
        $query .= "OR keywords LIKE '%$each%' "; 

    }

    //connect
    Mysql_connect ("localhost", "root","");
    Mysql_select_db("search");

    $query = mysql_query($query);
    $numrows = mysql_num_rows($query);
    if ($numrows > 0) {

        While ($row = mysql_fetch_assoc($query))  {
            $id = $row ['id'];
            $tittle = $row ['tittle'];
            $description = $row ['description'];
            $keywords = $row ['keywords'];
            $link = $row ['link'];

            echo "<h2><a href='$link'>$tittle</a></h2>
            $description<br /><br />";
    //disconnect
    mysql_close();

        }   

    }

    Else
        echo "No results found for \"<b>$k</b>\""

?

1 个答案:

答案 0 :(得分:0)

虽然您的问题编写得很糟糕且信息丢失,但问题可能是$i如果您在$i++声明之前if,则永远不会为0。

尝试在$i语句后添加if增量。

foreach ($terms as $each){
    if ($i == 0){
        $query .= "keywords LIKE '%$each%' "; 
    }else{
        $query .= "OR keywords LIKE '%$each%' "; 
    }
    $i++
}