Passing the results of a query(variable) to a third asp page and using it in another query

J

Jeff

I run the website for the Oneill High School Lacrosse Team.
http://www.oneilllax.org I have built this from scratch and am
learning as I go. Currently, the visitor clicks the link to view the
player statistics (www.oneilllax.org/selectplayerforquery.asp) and is
presented with a form. The drop down box presents the visitor with
the players names, but the option value that is passed via the form
is
actually db field of Player_PK. This variable is passed to the
following page via a Post from the form.

On the second page (www.oneilllax.org/playerstatisticsquery.asp) the
visitor is presented with serveral tables that result from the
various
queries using the Player_PK variable that was passed to this page.
This code was not hand written - but was generated using the Insert-

form->database results wizard. An example of the code string using


the variable passed to this page is:

fp_sQry="SELECT * FROM Player WHERE (Player_PK = ::player_PK::)"


This works great and selects the records from the current year
database. I used it all last year without any issues. If you hit
these links currently, there are no results, as we are just getting
into season and no games have been played yet.


Here is where I want to expand and make the site better. I want to
be
able to give the visitor (ie college scouts) the ability to look at
the previous year stats. So, I somehow needs to pass this Player_PK
variable to a new page. Within this new page, I will use the Insert-

form->database results wizard but I will use the appropriate


connector to connect to last year's database. If all works well, the
Player_PK variable will be passed to the page, the query will be run
against the 2006 database, and last years stats will be displayed.

Of course, the problem is that I dont know how to pass the variable
and then recapture it within FP (specifically within the database
results properties wizard from design view)


I have been googling for a week and have tried various combinations
of
hidden variable, sesson variable, request.form, response.write and
much more.


Looking and hoping for assistance.


Jeff
 
D

David Berry

How do you want to pass the variable (value) to the next page? Were you
thinking of using a hyperlink to pass the value? If so then you'd create a
QueryString in the hyperlink like this:

<a href="nextpage.asp?Player_PK=<%=Player_PK%>">Last Year's Database</a>

That assumes that "Player_PK" holds the value you want to pass. Then, on
the next page you'd grab that value like this:

Player_PK = Request("Player_PK")

Now you can use the variable Player_PK in your SQL Statement:

fp_sQry="SELECT * FROM Player WHERE (Player_PK = ::player_PK::)"
 
J

Jeff

David -
Thank you so much!!

I had in fact tried that solution before but it did not work. Now
I see why. I had not included the third equal sign below:

<a href="nextpage.asp?Player_PK=<%=Player_PK%>">Last Year's Database</
a>

Hope this may help others

Jeff
 
D

David Berry

Glad it helped. Yes, simple things like equals signs, variable names,
single quotes, double quotes and other things being in the right place can
drive you crazy. One tip, if something isn't working, is to use
Response.Write to "debug" your pages. For example, if you're passing a
value from one page to another and it's not getting there you can use
Response.Write to see what value is being passed. Ex:

Response.Write Player_PK

Or if your SQL statement isn't working you could do

Response.Write fp_sQry

This will display (in the browser) what the value is. When you see what the
value is (especially with a SQL Statement) it helps you debug the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top