[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Using Query_String but removing values from the string...

Posted on 2004-10-29
8
Medium Priority
?
180 Views
Last Modified: 2013-12-24
I want to allow my users to filter my table by each column by clicking on the header.  I am displaying the data from a query and then outputing it dynamically.  I want to pass the table name to sort by in the URL and also pass any other URL variables that exist in the QUERY_STRING CGI variable.  

The problem is that if I just use this: href="page.cfm?#QUERY_STRING#&orderby=fieldname" the next time a person clicks on a header from the same page their will be duplicate "orderby" values and it will mess up my query.  Is there an easy way to trim out the orderby value from the QUERY_STRING?  I figured that someone probably has run into this before, thanks!

Tim
0
Comment
Question by:Ike23
8 Comments
 
LVL 5

Expert Comment

by:kkhipple
ID: 12447914
well what i do when im working with sorting data is to do the following

<A HREF="page.cfm?tblName=#URL.tblName#&param=#URL.param#&orderby=#fieldname#">wahtever</A>


my opinion is that you probably  have structured the wrong way... i think what would be best Tim is that you paste some code and let us see what yo are exactly doing..


KDK
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 12450001
Hello Ike23!

You can simply do something like this :

<cfparam name="url.tblName" default="Table1">
<cfparam name="url.orderyby default="Column1">

<cfquery name="GetRecord" datasource="">
SELECT * FROM #url.tblName#
ORDER BY #url.orderyby#
</cfquery>

<!--- If you want to change the sorting of the same table --->
<cfset Header1= "?tblName=#url.Table1#&orderyby=Column1">
<cfset Header2= "?tblName=#url.Table1#&orderyby=Column2">
<cfset Header3= "?tblName=#url.Table1#&orderyby=Column3">

<!--- If you want to pass a certain table with specific sort order --->
<cfset Header4= "?tblName=Table1#&orderyby=Column1">
<cfset Header5= "?tblName=Table2#&orderyby=Column2">
<cfset Header6= "?tblName=Table3#&orderyby=Column3">

<!--- For the links and just assume this is within the column of a table. --->
<cfoutput>
  <a href="page.cfm#Header1#">Header1</a>
  <a href="page.cfm#Header2#">Header2</a>
  <a href="page.cfm#Header3#">Header3</a>
  <a href="page.cfm#Header4#">Header4</a>
  <a href="page.cfm#Header5#">Header5</a>
  <a href="page.cfm#Header6#">Header6</a>
</cfoutput>

Actually, if you are on the same page.  You may not include the filename on the "attribute href value".  You can simpy call <a href="#Header1#">Header1</a>.

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
 
LVL 4

Author Comment

by:Ike23
ID: 12464762
I have a bunch of different URL variables that don't relate to my query but that are needed for other aspects of the page.  I just want to filter out the orderby=whatever URL variables from the QUERY_STRING variable so that I can dynamically use this code all over my site when I want to pass all URL values except change one.  

Can I use the Replace() function somehow?  To be clear I want all the query_string to be passed everytime the header link is clicked so page.cfm?#Query_StringSpecial#&orderby=name.  I'm thinking that I can do a check before like

<cfif isdefined("QUERY_STRING")>
     <cfset QUERY_STRINGSPECIAL = Replace(QUERY_STRING,'orderby','','all') but I can't get it to work right.  

Thanks.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 17

Expert Comment

by:Tacobell777
ID: 12469686
Try
<cfset QUERY_STRINGSPECIAL = replaceNoCase(QUERY_STRING,'orderby','','all')/>

Or

<cfset QUERY_STRINGSPECIAL = reReplaceNoCase(QUERY_STRING, "&orderby=[^&]", "", "all")/>

I do believe you are making it hard for yourself
0
 
LVL 4

Author Comment

by:Ike23
ID: 12500395
I need to delete the entire name=value pair form the query string.  If you know of an easier way than I welcome the suggestion!  Here's what I ended up using.

<cfset newQS = ListDeleteAt(CGI.QUERY_STRING, ListContainsNoCase(CGI.QUERY_STRING, "orderby","&"),"&")>
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 12500842
Hi Ike23!

Try to evaluate this code, perhaps this is what you need :

<cfparam name="NewQS" default="">

<cfset QSLength = ListLen(cgi.QUERY_STRING,"&")>

<cfloop index="i" from="1" to="#QSLength#">
  <cfset thisParam =  ListGetAt(cgi.QUERY_STRING,i,"&")>
  <cfif FindNoCase('orderby',thisParam,1) eq 0>
    <cfif NewQS neq ''>
      <cfset NewQS = "#NewQS#&#thisParam#">
    <cfelse>
      <cfset NewQS = thisParam>
    </cfif>
  </cfif>
</cfloop>

<cfif NewQS neq ''>  
  <cfset Header1 = "#NewQS#&orderby=column1">
  <cfset Header2 = "#NewQS#&orderby=column2">
  <cfset Header3 = "#NewQS#&orderby=column3">
<cfelse>
  <cfset Header1 = "orderby=column1">
  <cfset Header2 = "orderby=column2">
  <cfset Header3 = "orderby=column3">
</cfif>

<cfoutput>
<a href="page.cfm?#Header1#">Header1</a><br>
<a href="page.cfm?#Header2#">Header2</a><br>
<a href="page.cfm?#Header3#">Header3</a><br>
</cfoutput>

Hope this helps you.  Just try it.


Regards!
eNTRANCE2002 :-)
0
 
LVL 4

Author Comment

by:Ike23
ID: 12507694
This works and is a lot less code:
<cfset newQS = ListDeleteAt(CGI.QUERY_STRING, ListContainsNoCase(CGI.QUERY_STRING, "orderby","&"),"&")>

Then I can pass all the required variables that run my page without having to type them all into the url string.  This will allow me to add an order by filter along with every other variable that was initially passed to the page since it can vary from client, user etc.  Thanks for trying though, I appreciate it.  You should try this code, it works pretty well and is only one line!

Tim
0
 
LVL 14

Accepted Solution

by:
Renante Entera earned 1000 total points
ID: 12510889
Yah! you're right Ike23...

I apologize for isolating your code.  Actually, it's really less code and simple.  I haven't think of that :-).

Anyway, I just only have one suggestion.  Apply also checking of the value for "CGI.QUERY_STRING", if there are cases that you use that code in which there's is no "URL" parameters being pass upon first browsing on a specific page.

For example : If a certain page that most parameters have been set to default values.  Have your checking like this :

<cfif ListContainsNoCase(cgi.query_string,"=","&") neq 0>
  <cfset newQS = ListDeleteAt(CGI.QUERY_STRING,ListContainsNoCase(CGI.QUERY_STRING, "orderby","&"),"&")>
</cfif>

Or if there are cases in which user attempts to type in the address bar something like : page.cfm?test.  It is expected that you will encounter an "Invalid list index 0" error in funtion ListDeleteAt.

Hope this helps you.


Regards!
eNTRANCE2002 :-)
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Media Temple is thrilled to announce the launch of our new Partner Program, specifically designed to empower digital agencies and adtech platforms by offering white-glove support and exclusive hosting enhancements to optimize their sites and their c…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question