Jump to content

Rollover $_GETs? Easier way to do it?


immanuelx2

Recommended Posts

echo '<a href="?';
if ($_GET['sort']) echo 'sort='.$sort.'&';
if ($_GET['flow']) echo 'flow='.$flow.'&';
if ($_GET['game_id']) echo 'game_id='.$_GET['game_id'].'&';
if ($_GET['server_id']) echo 'server_id='.$_GET['server_id'].'&';
echo 'page='.$pagenext.'">NEXT»</a>';

 

Is there an easier way to construct a link while keeping all the set $_GET values?

Link to comment
https://forums.phpfreaks.com/topic/55976-rollover-_gets-easier-way-to-do-it/
Share on other sites

Maybe store the URL in a variable?

 

<?php

$link = "";

if ($_GET['sort']) $link .= 'sort='.$sort.'&';
if ($_GET['flow']) $link .= 'flow='.$flow.'&';
if ($_GET['game_id']) $link .= 'game_id='.$_GET['game_id'].'&';
if ($_GET['server_id']) $link .= 'server_id='.$_GET['server_id'].'&';

echo '<a href="?'.$link.'?page='.$pagenext.'">NEXT»</a>';

?>

 

Other than that...it looks like a pretty solid method for putting together the link.

 

Here is a different approach at it....

 

<?php

$link = "";

foreach ($_GET as $key => $val){
   $link .= '&'.$key.'='.$val;
}

$link .= '&page='.$pagenext;

echo '<a href="'.$link.'">Test</a>';

?>

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.