I have a problem with this script.
everything works great until I try to go to the next page.
This is when I get the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/conference/admin/result.php on line 57
No Results Found!
Error, query failed.
Here is the code:
PHP Code:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
include("template_top.php");
include("connect.php");
$qsearch = $_POST['qsearch'];
$search_results = $_POST['qsearch'];
$search = $_POST['search'];
$exact = $_POST['exact'];
if ($search_results == "lastname") {
$search_results = "Last Name";
}
if ($search_results == "requiredorganization") {
$search_results = "Organization";
}
?>
<div id="content">
<div id="colOne">
<div class="post">
<h2 class="title">Search Results <?php echo $search_results ?></h2>
<h3 class="posted">
</h3>
<div class="story">
<p></p>
<?php
$qProfile = "SELECT * FROM options WHERE id='1'";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
extract($row);
$noa = stripslashes($noa);
// how many rows to show per page
$rowsPerPage = $noa;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
if ($exact) {
$query="SELECT * FROM application WHERE $qsearch LIKE '$search' ORDER BY
lastname ASC LIMIT $offset, $rowsPerPage";
$action = "WHERE $qsearch LIKE '$search'";
}
else {
$query="SELECT * FROM application WHERE $qsearch LIKE '%$search%' ORDER BY
lastname ASC LIMIT $offset, $rowsPerPage";
$action = "WHERE $qsearch LIKE '%$search%'";
}
$result=mysql_query($query);
$num = mysql_num_rows ($result);
if ($num > 0 ) {
$i=0;
while ($i < $num) {
$requiredname = mysql_result($result,$i,"requiredname");
$lastname = mysql_result($result,$i,"lastname");
$title = mysql_result($result,$i,"title");
$requiredemail = mysql_result($result,$i,"requiredemail");
$requiredorganization = mysql_result($result,$i,"requiredorganization");
$address = mysql_result($result,$i,"address");
$city = mysql_result($result,$i,"city");
$state = mysql_result($result,$i,"state");
$zip = mysql_result($result,$i,"zip");
$phone = mysql_result($result,$i,"phone");
$fax = mysql_result($result,$i,"fax");
$nysid = mysql_result($result,$i,"nysid");
$fdid = mysql_result($result,$i,"fdid");
$price = mysql_result($result,$i,"price");
$d = mysql_result($result,$i,"d");
$total = mysql_result($result,$i,"total");
$paydate = mysql_result($result,$i,"paydate");
$comment = mysql_result($result,$i,"comment");
$extra1 = mysql_result($result,$i,"extra1");
$extra2 = mysql_result($result,$i,"extra2");
$extra3 = mysql_result($result,$i,"extra3");
$id = mysql_result($result,$i,"id");
?>
<table border="0" width="100%">
<tr>
<td width="50%"><font color="#0000A0"><b>Last Name:</b></font></td>
<td>
<?
if ($search_results == "Last Name") {
echo "" . $tip = search_highlight($search, "<b><font style='color:white; background-color:blue;'>" . $search . "</font></b>", $lastname) . "";
}
else {
echo $lastname;
}
?>
</td>
</tr>
<tr>
<td width="50%"><font color="#0000A0"><b>First Name:</b></font></td>
<td><?php echo $requiredname ?></td>
</tr>
<tr>
<td width="50%"><font color="#0000A0"><b>Organization:</b></font></td>
<td>
<?
if ($search_results == "Organization") {
echo "" . $tip = search_highlight($search, "<b><font style='color:white; background-color:blue;'>" . $search . "</font></b>", $requiredorganization) . "";
}
else {
echo $requiredorganization;
}
?>
</td>
</tr>
<tr>
<td width="50%"><font color="#0000A0"><b>Date Payment Received:</b></font></td>
<td><?php echo $paydate ?></td>
</tr>
</table>
<BR>
<?
echo "<center><a href=\"update.php?id=$id&referpage=result\">View/Update</a> - <a href=\"delete.php?id=$id\">Delete</a></center>";
echo "<BR><BR>";
echo "<h3 class=\"seperator\"></h3>";
echo "<br>";
++$i; } } else { echo "<H3>No Results Found!</H3><br>"; }
$query = "SELECT COUNT(id) AS numrows FROM application $action";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
mysql_close();
if ($numrows <= $rowsPerPage) {
}
else {
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last] '; // nor 'last page' link
}
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last . "<br><br>";
}
function search_highlight($needle, $replace, $haystack)
{
$haystack = eregi_replace($needle,$replace,$haystack);
return $haystack;
}
include("template_bottom.php");
?>
Any help would be great, thanks