以下のスクリプトでこのエラーが発生し続けており、問題を解決する方法がわかりません。たくさんの記事を検索して読みましたが、取得できませんでした。私は何が欠けていますか?どんな助けでも心から感謝します!!
「警告: 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 ?>
<? } ?>