Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass query to new page?

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
I'm having a brain freeze here.... I think I once ran a query, moved it into a structure, and then passed the whole structure in the URL query string to a new page. Is this possible? I can't seem to do it today... Can I save an entire structure as a session variable?
 
yes you can...

<cfscript>
structName = StructNew();
structName.userID = queryName.pk_user;
structName.firstName = queryName.txt_FirstName;
structName.lastName = queryName.txt_LastName;
structName.userPermissions = queryName.txt_Permissions;

session.whatever = structName;
</cfscript>

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
Of course... lock as you go, for good measure.

And it's always a good idea to use Duplicate() when you're copying a structure to a new variable, and to clean up your structure with StructClear() after you're through with it.

Can't recall offhand whether lock is supported in CFSCRIPT... but regardless... something like:

Code:
<CFSCRIPT>
   structName = StructNew();
   structName.userID = queryName.pk_user;
   structName.firstName = queryName.txt_FirstName;
   structName.lastName = queryName.txt_LastName;
   structName.userPermissions = queryName.txt_Permissions;
</CFSCRIPT> 

<CFLOCK timeout=&quot;10&quot; type=&quot;EXCLUSIVE&quot; scope=&quot;SESSION&quot;>
   <CFSET session.whatever = Duplicate(structName)>
</CFLOCK>

<CFSET StructClear(structName)>



-Carl
 
um, how do you pass that in the URL string? and why would you?

rudy
 
You wouldn't.

junkjones kind of combined two questions into one... &quot;is it possible to pass a structure/query on the URL&quot; (it isn't)... and &quot;is it possible to save an entire structure as a session variable&quot; (it is).

Brannon concentrated on the later question... so I just stuck with that.


If junkjones really wanted to pass a structure on the URL (sans session variable), you could certainly do it manually... something like:

Example struct-
Code:
<cfscript>
myStruct = StructNew();
myStruct.var1 = &quot;hello world&quot;;
mystruct.var2 = &quot;foobar&quot;;
mystruct.var3 = &quot;M&M's&quot;;
</cfscript>

Manually construct the query string:
Code:
<CFSET myQueryString = &quot;&quot;>
<cfloop collection=&quot;#myStruct#&quot; item=&quot;whichKey&quot;>
<CFSET myQueryString = ListAppend(&quot;#myQueryString#&quot;,&quot;#URLEncodedFormat(whichKey)#=#URLEncodedFormat(mystruct[whichKey])#&quot;,&quot;&&quot;)>
</CFLOOP>

<CFIF Len(myQueryString) GT 256>
  Passing this structure on the URL may present problems for some browsers/operating systems.
</CFIF>

<CFOUTPUT><p><a href=&quot;nextpage.cfm?#myQueryString#&quot;>Pass the structure to nextpage.cfm</a></p></CFOUTPUT>



-Carl
 
thanks, carl

you're right, i wouldn't want to do that

i guess i was having another senior's moment

nice code, by the way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top