paging links by posting conditions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

paging links by posting conditions

Post by shivam0101 »

Hello,

I am using the below code to do paging

Code: Select all

function GetLinks($total,$minlimit,$limit,$file,$mstring="")
 {
	$limitto="";
	if($mstring=="")
		$mstring="minlimit";
	if($total>$limit) {
		if($minlimit!=0)
			$firstpglink="<a href='".$file."$mstring=0&limit=$limit'>First</a>";
		else
			$firstpglink="<span class='contentblackbold'>First</span>";
		if($limit != 0 && $total != 0) {
			if($total%$limit) {
				$lastcc=floor($total/$limit)*$limit;
			} else {
				$lastcc=(($total/$limit)-1)*$limit;
			}
			if($minlimit < $lastcc)
				$lastpglink="<a href='".$file."$mstring=$lastcc&limit=$limit' class='greentboldlink'>Last</a>";
			else
				$lastpglink="<span class='greentboldlink'>Last</span>";
		}
		if($minlimit>=$limit) {
			$prevcc=$minlimit-$limit;
			$prevpglink="<a href='".$file."$mstring=$prevcc&limit=$limit' class='greentboldlink'>Previous</a>";
		} else
			$prevpglink="<span class='greentboldlink'>Previous</span>";

		if($minlimit < (($total/$limit)-1)*$limit) {
			$nextcc=$minlimit+$limit;
			$nextpglink="<a href='".$file."$mstring=$nextcc&limit=$limit' class='greentboldlink'>Next</a>";
		} else
			$nextpglink="<span class='greentboldlink'>Next</span>";
		if(($minlimit+$limit)>$total)
			$limitto=$total;
		else
			$limitto=$minlimit+$limit;
		$links[0]="<table align='center' height='55' border='0' width='100%' cellpadding='4' cellspacing='4'><tr><td>$firstpglink</td><td>$prevpglink</td><td>$nextpglink</td><td>$lastpglink</td></tr></table>";
	}
	else
		$links[0]="";

	$links[1]="Showing ".($minlimit+1)."-".$limitto." of ".$total;
	return $links;
 }


usage

Code: Select all

$minlimit=$_GET['minlimit'];
		if(empty($minlimit))	$minlimit=0;
		$row=6;					$col=1;
		$limit=$row*$col;
		
		$tot=//sql statment to count the rows
				
		$sql_search=//sql statement for search		if($tot > 0)
		  {
			<table border=1 align='center' width='100%'>
			<tr><td>Photo</td> <td>Age - City - State - Country</td> <td>About me</td> 				
			 foreach($sql_search as $fetch_search)
			 {
                                                        //results
                                                 }
			$links=($tot,$minlimit,$limit,$_SERVER['PHP_SELF']."?process=search&cond=$cond");

The problem is, as i am posting using Get method, the search conditions are appearing in the address bar. As i am posting using Get method. How can i use the above using Post method, so that the coditions won't get displayed.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Change the form to use the post method. Switch $_GET references to $_POST. :?
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

when i click the link, its not posting
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Links don't post.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

then how do i pass the values?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Without Javascript's help, links can only GET.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

How to pass the value without javascript?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

If the paging isn't done by forms and buttons, just use links and _GET variables.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

If i user $_GET, the values are visible in the addressbar.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

just use a form to post your data.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

shivam0101 wrote:If i user $_GET, the values are visible in the addressbar.
And what variables would need to be hidden from the address bar?
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

the search conditions.

Actually i have a form in which the user will enter search conditions. If i use the POST method in form, the links wont work.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Most search engines do it all through the _GET method. Search the forums. Search Google. All in the URL.

It also allows users to bookmark search results for future use.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Forum searching is provided (by default) through post here. ;)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

feyd wrote:Forum searching is provided (by default) through post here. ;)
As far as I remember, not the paging or search queries.
Or do you mean phpBB in general?
Post Reply