如何修复:警告:mysql_num_rows():提供的参数不是有效的mysql结果资源


How to fix: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

我在下面的脚本中不断收到这个错误,不知道如何解决这个问题。我搜索和阅读了很多文章,但都没有找到。我缺少什么?衷心感谢您的帮助!!

"警告:mysql_num_rows():在第42行/home/content/37/8642937/html/settingsupsearch.php中,提供的参数不是有效的mysql结果资源"

<?php
$var = @$_GET['q'] ; // get the query for the search engine (if applicable)
$trimmed = trim($var); //trim whitespace from the stored variable
{
        $con = mysql_connect("***","***","***");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
}
$field = "title";
$query = mysql_query("SELECT * FROM Listings WHERE ($field) LIKE'%$trimmed%' ORDER BY id"); 
$result = mysql_query($query); 
?>
<form name="search" method="GET" action="<?=$PHP_SELF?>">
Search the database for: <input type="text" name="q" />
<input type="submit" name="search" value="Search" />
</form>
<?
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: &quot" . $trimmed . "&quot returned zero results</p>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s))
{
$s=0;
}
// get results
$result = mysql_query($query) or die("Couldn't execute query");
if($numrows > 1){ $return = "results";}
else{ $return = "result"; }
// display what the person searched for
echo "<p>Your search for &quot" . $var . "&quot returned $numrows $return.</p>";
// begin to show results set
$count = 1 + $s ;
while ($r= mysql_fetch_array($result))
{
$id = $r["ID"];
$title = $r["title"];
$date = $r["price"];
$city = $r["city"];
$count++ ;
?>
<a href="http://www.***.com/archive/<? echo $title ?>/<? echo $id ?>.html"><? echo $price ?></a>
<? echo $city ?>

<? } ?>

在查看代码时,似乎出现了一个错误:

$query = mysql_query("SELECT * FROM Listings WHERE ($field) LIKE'%$trimmed%' ORDER BY id"); 

它被封装在一个mysql_query中,然后用mysql_query再次调用它。