Search Script
Posted: Fri Nov 06, 2009 10:01 am
Hi there,
Below is a search script. It works fine when selecting results from one column, but when i try to select from multiple columns I get the following error...
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
The error is on the line containing the sql query.
Has anybody got any suggestions?
Below is a search script. It works fine when selecting results from one column, but when i try to select from multiple columns I get the following error...
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
The error is on the line containing the sql query.
Code: Select all
<?php
$var = @$_GET['q'] ;
$trimmed = trim($var);
$limit=10;
if ($trimmed == "")
{
echo "<span class='bodytext'> The search field was empty - please try again using the search form above </span><br>
<br>
<span class='bodytext'>If you are experiencing problems with this site please contact us <a href='contact_details.php' class='bodybold'>here</a></span>";
exit;
}
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
include("course_scripts/connect.php");
$query = "select * from course where courseTitle like \"%$trimmed%\ OR courseDescription like \"%$trimmed%\"
order by courseTitle";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<p class='bodytext'>Sorry, your search:<span class='numbers'> "" . $trimmed
. ""</span> returned zero results</p>";
}
if (empty($s)) {
$s=0;
}
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
echo "<table width='535' align='center' border='0' cellpadding='2' cellspacing='2' class='boxes'>
<tr>
<td><p class='titles'>You searched for: <span class='numbers'>"" .
$var . ""<br>
</span></td>
</tr>
</table><br>";
$count = 1 + $s ;
while ($row= mysql_fetch_array($result)) {
$courseTitle = $row["courseTitle"];
$courseID=$row["courseID"];
echo "<span class='bodybold'>$courseTitle - </span>";
echo '<a href="frontend_scripts/show_course.php?courseID='.$row["courseID"].'" class="links">View This Course</a><br><br>';
$count++ ;
}
$currPage = (($s/$limit) + 1);
echo "<br />";
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"search.php?s=$prevs&q=$var\" class='albumname'><< Prev 10</a>  ";
}
$pages=intval($numrows/$limit);
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"search.php?s=$news&q=$var\" class='albumname'>Next 10 >></a> ";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p class='numbers'>Showing results $b to $a of $numrows</p>";
?><br />
<br />
<img src="images/line_divider.gif" width="550" height="1" /><br /><br />
<span class="orangetitle">Esperan Tutorials...</span>
<?php
Has anybody got any suggestions?