Jump to content

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


timcadieux

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

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>

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.