Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass parameters to pagination url

Tags:

url

php

pdo

I am thing of a way to pass about 15 parameters to a url pagination:

for example I have:

$input = $_GET['input'];
$categories = $_GET['category'];
$state = $_GET['state'];
$zipcode = $_GET['zipcode'];

I could do it this way and works fine:

 $paginate.= "<a href='$targetpage?page=$prev&input=".$_GET['input']."& 
 category=".$_GET['category']."&state=".$_GET['state']."& 
 zipcode=".$GET['zipcode']."'>Previous</a>";

But I have a lot more Parameters to pass. Could someone show me how it's done using an array or anything better?

Thank you

like image 619
Che Jug Avatar asked Jan 03 '13 19:01

Che Jug


1 Answers

Yo can use this function:
http_build_query

php.net example:

<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";
echo http_build_query($data, '', '&amp;');

?>

Output:

foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
like image 107
Siamak Motlagh Avatar answered Oct 15 '22 04:10

Siamak Motlagh