Jump to content

Pagination + search


karimali831

Recommended Posts

Hi,

 

I'm using this pagination script at http://www.phpfreaks.com/tutorial/basic-pagination and works great.

I want to add a search to it and sort by ASC and DESC.

 

Here is what I added in between //Search and //End search:

 

// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='clans&currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='clans&currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
//Search

$search = $_POST['search'] ? $_POST['search'] : $_GET['search'];
$type = $_GET['type'];
$sort = $_GET['sort'];

if(!isset($sort)) $sort="ID";
if(!isset($type)) $type = "ASC";

if($search) 
	$ergebnis = safe_query("SELECT status, ID, name FROM ".PREFIX."cup_all_clans WHERE name LIKE '%$search%' ORDER BY $sort $type");
else 
	$ergebnis = safe_query("SELECT status, ID, name FROM ".PREFIX."cup_all_clans ORDER BY $sort $type");
$anz=mysql_num_rows($ergebnis);
if($anz) {	
	if($type=="ASC")
		$sorter='<a href="clans&sort='.$sort.'&type=DESC&search='.$search.'">Sort:</a> <img src="../images/icons/asc.gif" width="9" height="7" border="0">   ';
	else
	    $sorter='<a href="clans&sort='.$sort.'&type=ASC&search='.$search.'">Sort:</a> <img src="../images/icons/desc.gif" width="9" height="7" border="0">   ';

	echo '<form method="post" action="clans&sort='.$sort.'&type='.$type.'">'.$sorter.' Teamname: <input type="text" name="search" size="15" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'"> <input type="submit" value="Go"></form>';
   	if($search)
		echo '<p>'.$anz.' Clan(s) found</p>';

	echo'<form method="post" name="ws_cups" action="index.php?site=clans"><table width="100%" cellpadding="4" cellspacing="1" bgcolor="#999999">
       		<tr bgcolor="#CCCCCC">
	     		<td class="title" align="left"><a class="titlelink" href="clans&sort=name&type='.$type.'&search='.$search.'">Teams:</a></td></form>';

}
//End Search
// while there are rows to be fetched...
while($ds=mysql_fetch_assoc($result)) {

 

I'm getting correct output of "clans found" but not the correct teams showing.

It's just using page1, 2, 3 still when I use search.

 

I know above is incorrect. Someone please fix?

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/194775-pagination-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.