Return to Snippet

Revision: 8638
at October 1, 2008 11:00 by simplistik


Updated Code
<?php
	/**
	* Name: Preserve and update/rebuild query string<br>
	* @param Example:
	* Example URL: http://www.site.com/?category=foo&order=desc&page=2
	*
	* <a href="<?php echo queryString('order','asc'); ?>">Order ASC</a>
	*
	* Output HTML: <a href="?category=foo&amp;order=asc&amp;page=2">Order ASC</a>
	* Output URL: http://www.site.com/?category=foo&order=asc&page=2
	*
	* Not http://www.site.com/?category=foo&order=desc&page=2&order=asc
	*/
	function queryString($str,$val)
	{
		$queryString = array();
		$queryString = $_GET;
		$queryString[$str] = $val;
		$queryString = "?".htmlspecialchars(http_build_query($queryString),ENT_QUOTES);
		
		return $queryString;
	}
?>

Revision: 8637
at October 1, 2008 10:56 by simplistik


Updated Code
<?php
	/**
	* Name: Preserve and update/rebuild query string<br>
	* @param Example:
	* Example URL: http://www.site.com/?category=foo&order=desc&page=2
	*
	* <a href="<?php echo queryString('order','asc'); ?>">Order ASC</a>
	*
	* Output HTML: <a href="?category=foo&amp;order=asc&amp;page=2">Order ASC</a>
	* Output URL: http://www.site.com/?category=foo&order=asc&page=2
	*
	* Not http://www.site.com/?category=foo&order=desc&page=2&order=asc
	*/
	function queryString($str,$val)
	{
		$queryString = array();
		$queryString = $_GET;
		$queryString[$str] = $val;
		$queryString = "?".htmlspecialchars(http_build_query($queryString));
		
		return $queryString;
	}
?>

Revision: 8636
at October 1, 2008 10:54 by simplistik


Updated Code
<?php
	/**
	* Name: Preserve and update/rebuild query string<br>
	* @param Example:
	* Example URL: http://www.site.com/?category=foo&order=desc&page=2
	*
	* <a href="<?php echo queryString('order','asc'); ?>">Order ASC</a>
	*
	* Output HTML: <a href="?category=foo&amp;order=asc&amp;page=2">Order ASC</a>
	* Output URL: http://www.site.com/?category=foo&order=asc&page=2
	*
	* Not http://www.site.com/?category=foo&order=desc&page=2&order=asc
	*/
	function queryString($str,$val)
	{
		$queryString = array();
		$queryString = $_GET;
		$queryString[$str] = $val;
		$queryString = $_SERVER['REQUEST_URI']."?".htmlspecialchars(http_build_query($queryString));
		
		return $queryString;
	}
?>

Revision: 8635
at October 1, 2008 10:45 by simplistik


Initial Code
<?php
	/**
	* Name: Preserve and update/rebuild query string<br>
	* @param Example:
	* Example URL: http://www.site.com/?category=foo&order=desc&page=2
	*
	* <a href="<?php echo queryString('order','asc'); ?>">Order ASC</a>
	*
	* Output HTML: <a href="?category=foo&amp;order=asc&amp;page=2">Order ASC</a>
	* Output URL: http://www.site.com/?category=foo&order=asc&page=2
	*
	* Not http://www.site.com/?category=foo&order=desc&page=2&order=asc
	*/
	function queryString($str,$val)
	{
		$queryString = array();
		$queryString = $_GET;
		$queryString[$str] = $val;
		$queryString = $_SEVER['REQUEST_URI']."?".htmlspecialchars(http_build_query($queryString));
		
		return $queryString;
	}
?>

Initial URL

                                

Initial Description
Allows you preserve and update a query string and it's existing values easily, instead of constantly appending the new value to the end of the query string

Initial Title
Preserve & update/rebuild query string

Initial Tags
query, update

Initial Language
PHP