Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - QueryString parameters
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

QueryString parameters

 Post Reply Post Reply Page  <12
Author
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 27 June 2005 at 2:28pm


Private Function SmartQuery(ByVal strquerystrings, ByVal strValues)

dim strQuerystring
dim i
dim saryquerystrings
dim strquerystrings
dim strValues
dim saryValues

strQuerystring = "&" & Request.ServerVariables("QUERY_STRING")

saryquerystrings = Split(strquerystrings, "&")
saryValues = Split(";" & strValues, ";")

FOR i = 0 to unbound(saryquerystrings)

if not intstr(1, LCase(strQuerystring) , LCase(saryquerystrings (i)) & "=" & LCase(saryValues(i)) , vbTextCompare) then

strQuerystring = strQuerystring & "&" & saryquerystrings (i) &"=" & saryValues(i) & ""

end if

next

    'Return Function
    SmartQuery = strQuerystring
End Function




right the above should, but not tested get the existing querystring , then using the querystring veriables and values it checks each querystring parameter (strquerystrings), to see if it is within the querystring if its not it then gets the value (strValues), and adds "strquerystrings (value)=strValues (value)" to the querystring value


to activate it use

 SmartQuery(strquerystrings, strValues)

SET strquerystrings to all the querystring parameters (shw)

SET strValues to all the wanted values for that querystring (cds)

seperate strQuerystrings with & (dont start with one but always end with one

seperate strValues with ;

so for example

SmartQuery("swh&bid&","cds;33;")


i thin that will work let me know


Edited by dj air - 27 June 2005 at 2:30pm
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 28 June 2005 at 4:23pm
Thx, your function is good, but still don't address my needs, what I need is a way to make a link and only tell in that link the new querystring to use, always preserving any existing queries and checking for the presence of a query like the new one being put in.

Example, for paging, I use bp=6, it should remove bp=5 if it's there and only apply my new bp=6 always preserving all other queries in there.

Your function is good nevertheless, but with it I would still have to declare all queries in the link, what I want is to make a link like [<a href="" & thisFile & "?" & smartQuery("bp=" & bp + 1) & ">Next</a>] then the function smartQuery should:

- Gather all existing queries.
- Remove any bp=? already there and apply my new bp=?

See the point?

This is the first app I do which has alot of queries to be processed at any one time, I am the only one facing this problem?

I could offcourse declare all queries in all links, but then everytime I had a new query (like a new feature) I have to manually update all links to preserve that new query, too much trouble, there's gotta be a function controlling all this.

Help please.
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2005 at 8:53am
ok, the below version gets the querystring, then does the checks on parameter, then if it exists it deletes it and its value then adds the new one.



Private Function SmartQuery(ByVal strquerystrings, ByVal strValues)



dim strQuerystring
dim i
dim saryquerystrings
dim strquerystrings
dim strValues
dim saryValues
dim strTempQueryValue

strQuerystring = "&" & Request.ServerVariables("QUERY_STRING")

saryquerystrings = Split(strquerystrings, "&")
saryValues = Split(";" & strValues, ";")

FOR i = 0 to unbound(saryquerystrings)

' delete the parameter and value from the querystring
if intstr(1, LCase(strQuerystring) , LCase(saryquerystrings(i)) &"=", vbTextCompare) then


strTempQueryValue = request.querystring(saryquerystrings(i))
strQuerystring = replace(LCase(strQuerystring), Lcase("&" & saryquerystrings(i)) & "=" & strTempQueryValue , "")


strQuerystring = replace(LCase(strQuerystring), Lcase("?" & saryquerystrings(i)) & "=" & strTempQueryValue &"&" , "?")


END IF

' insert the new parameter
strQuerystring = strQuerystring & "&" & saryquerystrings (i) &"=" & saryValues(i) & ""


next

    'Return Function
    SmartQuery = strQuerystring
End Function




you execute like before but now it checks wheather the parameter already exists within the querystring, if it does it deletes it and its value.

sorry  for the late reply.


Edited by dj air - 29 June 2005 at 8:57am
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 02 July 2005 at 9:10pm
Hi, no problem, I have tested your function and it works however I'm still required to declare all queries in the link, not what I want to do.

On each link I just want to declare 1 query by that link and then the function does calculate what other queries already exist and fix the repeats.

Basicaly, if the querystring is now: fun.asp?op=ab&bid=33&cid=21&bp=16&shw=ops and I press the paging button to go to the next page, it should then be: fun.asp?op=ab&bid=33&cid=21&bp=17&shw=ops only bp=17 changed all the rest remains the same, this paging button has only a call to the function("bp=17") and the function does the rest.

I have done some work on it, but I'm now a bit lost, check and run this please:

<%

thisFile = "fun.asp"

Response.Write(vbCrLf & "<a href=""" & thisFile & "?op=ab&bid=33&cid=21&bp=16&shw=ops"">Lotsof</a><br><br>")

Response.Write(vbCrLf & "<a href=""" & thisFile & """>None</a><br><br>")

Response.Write(vbCrLf & "<a href=""" & thisFile & "?" & sQuery("shw=cds") & """>Query</a>")


'// [=======================================================]
'// [=| sQuery                                           |=]
'// [=======================================================]
Function sQuery(ByVal strMyQuery)

Dim strQueryFull, arrVarAndValue, arrVar, arrMyVar, arrMyValue, query, var

strQueryFull = Request.ServerVariables("QUERY_STRING")

arrVarAndValue = Split(strQueryFull, "&")

'// Get my variable not value with arrMyVar(0)
arrMyVar = Split(strMyQuery, "=")

For query = 0 to UBound(arrVarAndValue)
    If LCase(arrVarAndValue(query)) = strMyQuery Then strMyQuery = ""
    Response.Write(vbCrLf & "<b>Query: " & arrVarAndValue(query) & "</b><br>")

    arrVar = Split(arrVarAndValue(query), "=")

    For var = 0 to UBound(arrVar)
      If var Mod 2 Then Response.Write(vbCrLf & "Var only: " & arrVar(var Mod 1) & "<br>")
    Next

    Response.Write("<br>")
Next


If strMyQuery = "" Then
    sQuery = strQueryFull
ElseIf strQueryFull = "" Then
    sQuery = strMyQuery
Else
    sQuery = strQueryFull & "&" & strMyQuery
End If

End Function
'// --------------------------| End of function: sQuery
%>


See what I need is to make a link like: Response.Write(vbCrLf & "<a href=""" & thisFile & "?" & sQuery("shw=cds") & """>Query</a>") -- Then the function will decimate what's already in the querystring by the & sign, then for each found it will seperate var/value by the = sign, then compare the var with the var I'm passing to the function and it is there already change only the value, so if the URL already contains and shw=ops and my link has shw=cds the old shw=ops should disappear in favor of my one.
Back to Top
TrendSetterX View Drop Down
Newbie
Newbie


Joined: 23 July 2005
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TrendSetterX Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2005 at 1:39pm

This code should solve all your problems, plus. The first method depends on the other two, which are equally useful on their own.  You'll need to remove the &nnbs p; that the board added in the one function.

/// <summary>
/// Appends string items together with a specific string separating the items. Unless false is
/// specified for AppenWhenListItemIsEmpty, an empty ListItem item will be appended.  If true is
/// specified for AppendWhenListItemIsNull, a null ListItem will be appended as an empty string.
/// </summary>
/// <param name="List">The list to append to</param>
/// <param name="ListItem">The item to be appended to the list</param>
/// <param name="ListItemSeparator">The string that will separate the list from the new item</param>
/// <param name="AppendWhenListItemIsNull">
/// If true, a null ListItem should be appened as an empty string. 
/// If false, a null ListItem will cause the List to be returned as-is without any modification.
/// </param>
/// <param name="AppendWhenListItemIsEmpty">
/// If true, an empty ListItem should be appened. 
/// If false, an empty ListItem will cause the List to be returned as-is without any modification.
/// </param>
/// <returns>A separated string</returns>
public static string AppendListItems(string List, string ListItem, string ListItemSeparator, bool AppendWhenListItemIsNull, bool AppendWhenListItemIsEmpty)
{
      string ret = string.Empty;
 
      if ((!AppendWhenListItemIsNull && ListItem == null) || (!AppendWhenListItemIsEmpty && ListItem.Trim().Length == 0))
      {
            ret = List;
      }
      else
      {
 
            // Validate the ListItemSeparator argument
            if (ListItemSeparator == null)
            {
                &nbs p; throw new System.ArgumentNullException("ListItemSeparator");
            }
 
            // Clean the ListItem argument
            if (ListItem == null)
            {
                &nbs p; ListItem = string.Empty;
            }
 
            // Append the list items
            if (List == null || List == string.Empty)
            {
                &nbs p; ret = ListItem;
            }
            else
            {
                &nbs p; if (List.EndsWith(ListItemSeparator))
                &nbs p; {
                &nbs p;       ret = List + ListItem;
                &nbs p; }
                &nbs p; else
                &nbs p; {
                &nbs p;       ret = List + ListItemSeparator + ListItem;
                &nbs p; }
            }
      }
     
      // Return the result
      return ret;
}
 
 
 
/// <summary>
/// Appends a name and value onto a querystring as a name=value pair.
/// </summary>
/// <param name="QueryString">The Querystring to add the items to</param>
/// <param name="Name">The Name part of the pair</param>
/// <param name="Value">The Value part of the pair</param>
/// <param name="ReplaceNameValuePairIfNameAlreadyPresent">Whether or not to replace the
/// name value pair with the new name value pair if the name already exists</param>
/// <param name="AppendValueToNameIfNameAlreadyPresent">Whether or not to include the
/// value as a subvalue of Name if Name already exists in the querystring.  If
/// ReplaceNameValuePairIfNameAlreadyPresent is true, this value is ignored</param>
/// <returns></returns>
public static string AppendNameValuePairToQueryString(string QueryString, string Name, string Value, bool ReplaceNameValuePairIfNameAlreadyPresent, bool AppendValueToNameIfNameAlreadyPresent)
{
      string ret = string.Empty;
 
      if (!(Name == null || Value == null || Name.Trim().Length ==0 || Value.Trim().Length == 0))
      {
            // Clean the querystring
            if (QueryString == null)
            {
                &nbs p; QueryString = string.Empty;
            }
            else
            {
                &nbs p; QueryString.Trim(' ', '&');
            }
 
            bool nameAlreadyPresent = (QueryString.IndexOf("?"+Name+"=") >= 0 || QueryString.IndexOf("&"+Name+"=") >= 0);
           
            // Add the value onto the end of the existing name=value pair with a comma between
            //  the added value and the previous value
            if (nameAlreadyPresent && (ReplaceNameValuePairIfNameAlreadyPresent || AppendValueToNameIfNameAlreadyPresent))
           
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2005 at 9:12pm
Hi,
Is it client side javascript?

I prefer not to use any client side javascript as it can be turned off, so rendering my app useless, I don't even do form validation that way any more for the same reason, and, I hate not being able to access a web site or link because it relies on javascript, which I always have off, and so most security consciencious people.

If it is server side javascript, all my code is in VBSCript so can't use it either.

Thanks anyway, appreciatted it.
Back to Top
TrendSetterX View Drop Down
Newbie
Newbie


Joined: 23 July 2005
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TrendSetterX Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2005 at 9:17pm
It's actually asp.net/c# code.  Thanks for appreciating... :)
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.