我在下面的脚本中不断收到此错误,并且不确定如何解决此问题。我已经搜索并阅读了大量文章,但没有得到它。我错过了什么?真诚感谢任何帮助!
“警告:mysql_num_rows():提供的参数不是第 42 行 /home/content/37/8642937/html/settingupsearch.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: "" . $trimmed . "" 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 "" . $var . "" 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 ?>
<? } ?>