Zend - The PHP Company




HTML

Add Code


Add values to query string  

Type: code fragment
Added by: ADMIN
Entered: 18/01/2000
Last modified: 08/12/1999
Rating: **** (8 votes)
Views: 10175
This function allows to form query string with a values added to it from current query string


<?php
function query_string($q_arr) {
    global 
$HTTP_GET_VARS,$PHP_SELF;
    
$str "$PHP_SELF?";
    
reset($q_arr);
    while(list(
$k,$v) = each($q_arr)) {
    
$str .= "$k=$v&";
    }
    
reset($HTTP_GET_VARS);
    while(list(
$k,$v) = each($HTTP_GET_VARS)) {
    if(isset(
$q_arr[$k])) continue;
    
$str .= "$k=$v&";
    }
    return 
$str;
}
?>


Usage Example


we call query.php?var=val, then in query.php:

<a href="<? echo query_string(array("var2" => "val2,
                   "
var3" => "val3"));
?>"
>Add val2 and val3</a>


Rate This Script





Search



This Category All Categories