Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 16th, 2007, 08:14 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Request.Form / Request.QueryString

Hello Everyone
there is a puzzel i do not understand and need some help with:

A form generates dynamic fields i do not know how many fields are generated. A user inputs some data to save into the fields, and submits.

The recieving page cycles through Request.Form (or Request.QueryString, i have tryed both) and save the data into a database using a for ech loop.

Suddenly all get's whakko because the data will be saved out of order in which it was received.

here is some code to show what i mean:

response.write Request.QueryString + "<br><br>"

for each item in request.QueryString
 response.write (item + " - " + Request.QueryString(item) + "<br>")
next




this is the result:

CASE1=1&HYDR1=2&HYDR2=3&HYDR3=4&MOVE1=5&MOVE2=6&MO VE3=7&PFRP1=8&PFRP2=9&PFRP3=10

CASE1 - 1
HYDR1 - 2
PFRP2 - 9
HYDR2 - 3
PFRP3 - 10
HYDR3 - 4
MOVE1 - 5
MOVE2 - 6
MOVE3 - 7
PFRP1 - 8

is there any way to get the For loop to go through the string in the right (1st) order??

the result should look like:
CASE1 - 1
HYDR1 - 2
HYDR2 - 3
HYDR3 - 4
MOVE1 - 5
MOVE2 - 6
MOVE3 - 7
PFRP1 - 8
PFRP2 - 9
PFRP3 - 10

Help is much appreciated.




... there is always more to learn...
__________________
... there is always more to learn...
  #2 (permalink)  
Old January 16th, 2007, 09:13 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope

Woody Z
http://www.learntoprogramnow.com
  #3 (permalink)  
Old January 16th, 2007, 11:13 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm new, but an approach that seems likely to produce the desired result would be to set variables for the individual fields inside the for loop, and then pass the variables in as parameters to your stored procedure or query immediately after the loop.
eg: case_1=Request.Form.Item("CASE1")
     hydr_1=Request.Form.Item("HYDR1")
     hydr_2=Request.Form.Item("HYDR2")
to set your variables

UPDATE tablename SET case1 = '" & case_1 & "'hydr1 = '" & hydr_1 & "'hydr2 = '" & hydr_2 & "'"
to pass the variables in as parameters.

If you use a stored procedure you can set parameters to have NULL as their default value, and that should help you get past the problem of not knowing which fields will be used. Just write for all possible parameters and let any missing fields get set to NULL in the stored procedure.




  #4 (permalink)  
Old January 17th, 2007, 10:59 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your suggestion.
The snippet i posted is only one of many possible scenarios.
The fields that feed the page in question may or may not be generated in the first place. So there may be no item called Request.QueryString("Hydro") at all. it could start with PFRP and it could be the only item (next to CASE which is mendentory).

Fact is i am thinking of breaking the QueryString up in its individual items and put it in an array... bubble sort the array then loop through the array... but whet is the best way to cut up the string?


... there is always more to learn...
  #5 (permalink)  
Old January 17th, 2007, 02:23 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am not sure what you mean: "What is the best way to cut up the string" if you mean what would be the easiest way to get individual elements, you would grab the entire query string and then split on '&' that will give you individual elements so

CASE1=1&HYDR1=2&HYDR2=3&HYDR3=4&MOVE1=5&MOVE2=6&MO VE3=7&PFRP1=8&PFRP2=9&PFRP3=10

becomes

CASE1=1
HYDR1=2
PFRP2=9
HYDR2=3
PFRP3=10
HYDR3=4
MOVE1=5
MOVE2=6
MOVE3=7
PFRP1=8

not in that order of course

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
Request.Querystring ms_code_bsuter ASP.NET 1.0 and 1.1 Basics 1 February 10th, 2006 08:10 PM
Problem with Request.QueryString mg1966 Classic ASP Databases 4 January 7th, 2005 02:04 PM
request querystring dannyphw ASP.NET 1.0 and 1.1 Basics 1 October 25th, 2004 10:35 AM
request.qurystring vs. request.form Durwood Edwards Classic ASP Databases 3 June 18th, 2004 12:09 AM
request.querystring() , request.form() alyeng2000 ASP.NET 1.0 and 1.1 Basics 1 December 30th, 2003 12:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.