Hi, i am having problems displaying the second page of search results. I have applied similar code to a view all logs page which works perfectly but i am having problems making it work with search results. I think it might be a problem with $searchString, not sure???
Please help me!!!:icon_neutral:

Here is the code --------->

//save keyword from html search form to variable
$searchString2 = addslashes($_POST['search2']);

if(!empty($searchString2)) {
// how many rows to show per page
$rowsPerPage = 20;

// 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; 
$query = "SELECT * FROM fishinglog WHERE username LIKE '$searchString2' AND private = 'no' ORDER BY date11_date DESC LIMIT $offset, $rowsPerPage ";
$result = mysql_query($query);
Print "<h3>Search Results for Username: <font color='#76b8f2'>'$searchString2' </font></h3><br />";
Print "<BR>Submit a <a href=newlog.php>Fishing Log</a><BR>";
Print "<BR><a href=viewyourlogs.php>View</a> your Fishing Logs<BR>";
Print "<BR><a href=searchlogs.php>Search</a> members Fishing Logs<BR><BR>";
Print"<hr>";
Print"<table>";
$anymatches01=mysql_num_rows($result);
if ($anymatches01 != 0) {
Print"<tr><td><font color=#00CCff>Fishing Location</font></td><td><font color=#00CCff>Date</font></td><td><font color=#00CCff>Action</font></td><td><font color=#00CCff>Created by</font></td>";
}else{
Print"";
}
while ($i = mysql_fetch_array($result)){
print <<<END
<tr><td width=200><a href="displaylog.php?fishing_location=$i[fishing_location]&&id=$i[id]">$i[fishing_location]</a></td><td width=100>$i[date11_date] $i[date11_month] $i[date11_year]</td><td width=70>$i[action]</td><td><a href="userinfo.php?user=$i[username]">$i[username]</a></td>

END;
} 
Print"</table>";
// how many rows we have in database
$query   = "SELECT COUNT(*) AS numrows FROM fishinglog WHERE username LIKE '$searchString2' AND private = 'no'";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav  = '';

for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
      $nav .= " $page "; // no need to create a link to current page
   }
   else
   {
      $nav .= " <a href=\"$self?page=$page\">$page</a> ";
   }
}
// creating previous and next link
// plus the link to go straight to
// the first and last page

if ($pageNum > 1)
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
   $prev  = '&nbsp;'; // we're on page one, don't print previous link
   $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
   $next = '&nbsp;'; // we're on the last page, don't print next link
   $last = '&nbsp;'; // nor the last page link
}

// print the navigation link
echo"<br>";
echo "<center>";
echo $first . $prev . $nav . $next . $last;
echo "</center>";
if ($anymatches01 == 0) {
echo "Sorry, but your search criteria matched no results<br><br>";
//And we remind them what they searched for
echo "<b><a href=searchlogs.php>Search again</a><br><br>";
}
}

i still have this problem p please help!

hai billy

look into this thread here the same problem you are having is solved.

http://www.webmasterworld.com/forum88/9860.htm

you have to change the start page code?.

if you are not sure use that code given in that site. and change the portion

if(!isset($_GET)) { // This variable is set to zero for the first page
$start = 0;
} else {
$start = $_GET;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.