Jump to content

Need some help using the QueryString to allow users to further filter data in a grid


timcadieux
Go to solution Solved by ignace,

Recommended Posts

so I built a simple grid that loads data based on params sent via the querystring.  I'm using the same backend for both a Simple Search and Advanced Search.

 

What I happend is a Search for Last Name and Firstname, this appears like ?lname=foo&fname=morefoo

 

However, when my grid appears, I dsiplay ALL data related to that user on a row, ie Country, State, etc.

 

What I want to be able to do have the CountryName hyperlinked with the params from the existing querystring and add the new params so that the querystring looks like ?lname=foo&fname=morefoo&countryId=65&stateId=129

 

My problem is that the Advanced search allows a user to query on these fields via dropdown, but the are Optional.  Therefore I can often end up with ?lname=foo&fname=morefoo&countryId=&stateId=

 

I need to be able to use a function that will allow me to replace an existing parm if it exists and/or append if it does not.  Does that make sense.  Something that would eventually look like the below

echo '<td><a href=view-paginated.php?' . merge_querystring('countryID' , $row[13] ) . ' class=nodecoration>' . $row[13] . '</a></td>';								
						

any help would be appeciated

Link to comment
Share on other sites

  • Solution

function addOrReplaceParam($params, $value = null) {
  if ($value !== null) {
    $params = array($params => $value);
  }
  return http_build_query(array_merge($_GET, $params));
}
You can use it like:

 

<a href="foo.php?<?= addOrReplaceParam('foo', 'bar') ?>">foobar</a>
Or like

 

<a href="foo.php?<?= addOrReplaceParam(array('foo' => 'bar', 'bat' => 'baz')) ?>">more foobar</a>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.