views:

30

answers:

1

I've done this a long time ago, now I can't find the function. It shouldn't be too complicated, but I wonder if there's any news on this before I go and do it again...

Take this:

www.example.com?query=whatever&page=1

Now imagine I press button to page 2, it will become:

www.example.com?query=whatever&page=2

Always keeping the rest of the querystring intact. Now picture on page 2 I press the button to order by date, it should turn into:

www.example.com?query=whatever&page=1&order=date

Problem is, on the ASP code for ordering, I don't want to handle every other querystring. So I need a function to handle it for me and be able to do something like the following examples:

<a href="?<%= add_querystring(qs, "order", "date") %>">date</a>
<a href="?<%= set_querystring(qs, "page", page + 1) %>">next page</a>
<a href="?<%= add_querystring(del_querystring(qs, "page"), "allpages") %>">all pages</a>

This is just an initial idea of what I am going to do if I still can't find a ready solution... Again, just wondering if there's anything new out there to handle all this in ways I haven't even imagined yet.

A: 

If it's of anyone's interest, here's the quite confusing code I rolled on yesterday:

'Build a string QueryString from the array Request
function bdl_qs (req_qs)
    dim result, qa, item
    result = empty
    qa = "?"
    if isnull(req_qs) or isempty(req_qs) then req_qs = Request.QueryString
    for each item in req_qs
        result = result & qa & item
        result = result & "=" & req_qs(item)
        qa = "&"
    next
    bdl_qs = result
end function

'Build a string QueryString ontop of the supplied one, adding the query and / or value(s) to it
function add_qs (qs, q, s)
    dim result
    result = qs
    if left(result, 1) = "?" then
        result = result & "&" & q
    else
        result = "?" & q
    end if
    if not isnull(s) and not isempty(s) then 
        result = result & "=" & s
    end if  
    add_qs = result
end function

'Build a string QueryString ontop of the supplied one, removing the selected query and / or values
function del_qs (qs, q)
    dim result, item
    result = qs
    if left(qs, 1) = "?" then
        dim rqs, qa
        rqs = result
        result = "?"
        rqs = right(rqs, len(rqs)-1) 'remove the "?"
        rqs = Split(rqs, "&") 'separate the queries
        qa = ""
        for each item in rqs
            dim rq
            rq = Split(item, "=") 'separate the query to analyze the name only
            if rq(0) <> q then 'good for rebuilding
                result = result & qa & item
                qa = "&"
            end if
        next
    end if
    del_qs = result
end function

'Build a string QueryString ontop of the supplied one, setting the query to the value
function set_qs (qs, q, s)
    set_qs = add_qs(del_qs(qs, q), q, s)
end function
Cawas