Database Results Using Page Variable

M

Max123

Hello, can someone please tell me how I can declare a variable on my asp page
and then have a database results region filter records using the value of
that variable?

Purpose: I have a series of articles (pages) that have mostly static
content, but there is some additional data in a database (fields such as
Author and Date Written). On each article page there is a Include Page which
contains the database results region using formatting that is too laborious
to reproduce manually on each article page (hence the include page).

So I'd like to declare a variable (something like ArticleID = 123) and then
specify the ArticleID variable in the Criteria of the database results wizard.

Thanks for any assistance!
 
S

Stefan B Rusynko

You can do it w/ a pick list page
See http://spiderwebwoman.com/tutorials/picklist_with_dropdown.htm




| Hello, can someone please tell me how I can declare a variable on my asp page
| and then have a database results region filter records using the value of
| that variable?
|
| Purpose: I have a series of articles (pages) that have mostly static
| content, but there is some additional data in a database (fields such as
| Author and Date Written). On each article page there is a Include Page which
| contains the database results region using formatting that is too laborious
| to reproduce manually on each article page (hence the include page).
|
| So I'd like to declare a variable (something like ArticleID = 123) and then
| specify the ArticleID variable in the Criteria of the database results wizard.
|
| Thanks for any assistance!
 
M

Max123

Thank you for your reply Stefan.

The pick list solution seems to require that the user submit a form. Also,
it doesn't appear to involve an include page. I'm not sure how it pertains
to my question.

To repeat, I have a collection of article pages that all incorporate the
same include page. But the database results in the include page should show
a different record depending on which article page is displayed. The purpose
is to show some details about the author without having to manually reproduce
the database results on each page. If this is unclear, I can elaborate
further.

Perhaps you know the answer to this question: When specifying Criteria in a
database results, what syntax is used when entering a variable declared on
the page?

Thank you, Max
 
S

Stefan B Rusynko

You can modify the Pick list example to use a hyperlink to pass the query (your criteria)
See http://www.outfront.net/spooky/search_hyper.htm
Each link to a specific page would pass the criteria field value as in
<A href="yourpagename.asp?ArticleID=123">See Article 123</a>

Right above the 1st grey code just enter the ASP code to get the query value from the sending page
<% Request.QueryString("ArticleID") %>

The page will fail if the query is empty so you need to pass all links to the pages w/ a query string and valid value for ArticleID

PS
Not relevant that you use a FP Include page for the DBRW since it is a design time component and all content inside of the BODY tags
is included in the page being processed so to ASP it is 1 page




| Thank you for your reply Stefan.
|
| The pick list solution seems to require that the user submit a form. Also,
| it doesn't appear to involve an include page. I'm not sure how it pertains
| to my question.
|
| To repeat, I have a collection of article pages that all incorporate the
| same include page. But the database results in the include page should show
| a different record depending on which article page is displayed. The purpose
| is to show some details about the author without having to manually reproduce
| the database results on each page. If this is unclear, I can elaborate
| further.
|
| Perhaps you know the answer to this question: When specifying Criteria in a
| database results, what syntax is used when entering a variable declared on
| the page?
|
| Thank you, Max
|
| "Stefan B Rusynko" wrote:
|
| > You can do it w/ a pick list page
| > See http://spiderwebwoman.com/tutorials/picklist_with_dropdown.htm
| >
| > --
| >
| > _____________________________________________
| > SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
| > "Warning - Using the F1 Key will not break anything!" (-;
| > To find the best Newsgroup for FrontPage support see:
| > http://www.net-sites.com/sitebuilder/newsgroups.asp
| > _____________________________________________
| >
| >
| > | Hello, can someone please tell me how I can declare a variable on my asp page
| > | and then have a database results region filter records using the value of
| > | that variable?
| > |
| > | Purpose: I have a series of articles (pages) that have mostly static
| > | content, but there is some additional data in a database (fields such as
| > | Author and Date Written). On each article page there is a Include Page which
| > | contains the database results region using formatting that is too laborious
| > | to reproduce manually on each article page (hence the include page).
| > |
| > | So I'd like to declare a variable (something like ArticleID = 123) and then
| > | specify the ArticleID variable in the Criteria of the database results wizard.
| > |
| > | Thanks for any assistance!
| >
| >
| >
 
M

Max123

Thanks again for your reply Stefan. Your advice is appreciated...I'm just
hoping you or someone else has a little more advice that relates to my
situation. I'll describe it more fully so you can have a better
understanding of what I'm doing.

- The site has 100+ Article pages that each have an "About the Author"
section.
- All the content on an Article page is static html except the Author section.
- The Author Section displays data such as AuthorName and AuthorDate from a
table using FP Database Results.
- The Author Section is in an include page because if I ever want to change
the *design* of the Section, I don't want to have to modify 100+ pages.
- Site Visitors do not click anything once they get to an article page. The
Author Section should be populated and appear at the same time the page
loads. Visitors should not have to click a hyperlink or submit a form to see
the Author Section.
- The Database Results needs to be passed the ArticleID so that it only
displays the one record that pertains to the article.

The ArticleID cannot be passed to the DBR via a hyperlink or query string
because the information is supposed to appear when the page loads. I am
hoping there is some way to specify a criteria in the DBR that refers to a
variable declared on the page. This would be a variable declared in asp
code, not a value passed from a link or appearing in a query string.

1. I imagine it is fairly simple to declare a variable called ArticleID on
a page. Can you tell me how to do that?
2. And do you know what syntax to use to specify that variable in a DBR
Criteria?

If you or anyone could answer those two questions I would be extremely
grateful.

Kind regards, Max
 
M

Max123

Thanks again for your reply Stefan. Your advice is appreciated...I'm just
hoping you or someone else has a little more advice that relates to my
situation. I'll describe it more fully so you can have a better
understanding of what I'm doing.

- The site has 100+ Article pages that each have an "About the Author"
section.
- All the content on an Article page is static html except the Author section.
- The Author Section displays data such as AuthorName and AuthorDate from a
table using FP Database Results.
- The Author Section is in an include page because if I ever want to change
the *design* of the Section, I don't want to have to modify 100+ pages.
- Site Visitors do not click anything once they get to an article page. The
Author Section should be populated and appear at the same time the page
loads. Visitors should not have to click a hyperlink or submit a form to see
the Author Section.
- The Database Results needs to be passed the ArticleID so that it only
displays the one record that pertains to the article.

The ArticleID cannot be passed to the DBR via a hyperlink or query string
because the information is supposed to appear when the page loads. I am
hoping there is some way to specify a criteria in the DBR that refers to a
variable declared on the page. This would be a variable declared in asp
code, not a value passed from a link or appearing in a query string.

1. I imagine it is fairly simple to declare a variable called ArticleID on
a page. Can you tell me how to do that?
2. And do you know what syntax to use to specify that variable in a DBR
Criteria?

If you or anyone could answer those two questions I would be extremely
grateful.

Kind regards, Max
 
S

Stefan B Rusynko

If I understand you correctly your pages are static html Except for a section of the page (again forget it is an include) which
pulls something from a DB (your author info)
- that means to get to a static article page a user must click on a link (or if it comes from a search page at least Open the
correct page) for any specific static article (forget the author info for now)

You are attempting the impossible
ASP code is processed server side before it is rendered client side
You want it to "guess" what's on the page before the static page is rendered and decide what to add to that specific page
- How is supposed to guess (before the static page is rendered) what your static content is for any page is?
Only if you:
- pass info to the page from a link (query or form)
- or in the top of each unique static page (not your include page) declare a ASP variable for your include page to use
say
<% ArticleID=123 %>





| Thanks again for your reply Stefan. Your advice is appreciated...I'm just
| hoping you or someone else has a little more advice that relates to my
| situation. I'll describe it more fully so you can have a better
| understanding of what I'm doing.
|
| - The site has 100+ Article pages that each have an "About the Author"
| section.
| - All the content on an Article page is static html except the Author section.
| - The Author Section displays data such as AuthorName and AuthorDate from a
| table using FP Database Results.
| - The Author Section is in an include page because if I ever want to change
| the *design* of the Section, I don't want to have to modify 100+ pages.
| - Site Visitors do not click anything once they get to an article page. The
| Author Section should be populated and appear at the same time the page
| loads. Visitors should not have to click a hyperlink or submit a form to see
| the Author Section.
| - The Database Results needs to be passed the ArticleID so that it only
| displays the one record that pertains to the article.
|
| The ArticleID cannot be passed to the DBR via a hyperlink or query string
| because the information is supposed to appear when the page loads. I am
| hoping there is some way to specify a criteria in the DBR that refers to a
| variable declared on the page. This would be a variable declared in asp
| code, not a value passed from a link or appearing in a query string.
|
| 1. I imagine it is fairly simple to declare a variable called ArticleID on
| a page. Can you tell me how to do that?
| 2. And do you know what syntax to use to specify that variable in a DBR
| Criteria?
|
| If you or anyone could answer those two questions I would be extremely
| grateful.
|
| Kind regards, Max
 
M

Max123

Thank you for answering Question #1 Stefan...I'm halfway there!

You said, "in the top of each unique static page (not your include page)
declare a ASP variable for your include page to use say <% ArticleID=123 %>".
This sounds perfect! So is this the full code:
<% ArticleID=123 %>
or is additional code necessary to declare a variable? Also, does this go
in <head> or <body>?

Now that the page knows what article it is displaying, let's move on to
question #2 from my previous post. What syntax do I enter in the DBR Wizard
to refer to this variable?

We're almost there!

Thanks again, Max
 
M

Max123

Hi Kathleen,

There could be several ways to get to an article page:
- Click a link on the home page
- Click a link on a page that lists all articles
- Click a link in an email
- Click a link on a related article page
- Enter the URL in a browser

The article page filename URLs are hardcoded to the article, for example:
/articles/A1234.asp

It would be really cool if some code on the page could derive the article ID
from the filename. The (five-character) article ID is always the page's file
name (without the ".asp" extension). If this is not possible, I am okay with
manually declaring a variable (a method Stefan discusses in a thread parallel
to this one).

Do you know of a web resource that shows example code for simple functions
such as:
- Declare a variable
- Manipulate a variable
- Populate a variable with the URL of the current page
- Etc.

I have used databases and query strings extensively and found that they
usually satisfy my needs. But in this one case (multiple static html pages
with a common DBR region) they don't seem appropriate so I am looking for a
solution which requires a bit of code.

Thank you, Max
 
S

Stefan B Rusynko

Depends on your DB field types and names

If you are running a qry (DBRW) against your table for the "authors info" w/ an article # (field name ArticleID is in the table)
then you set the Criteria (More Options in the DBRW) to select ArticleID Equals ArticleID
As for declaring it, it depends on your actual field type

Numeric fields are declared w/o delimiters and text fields w/ delimiters
Number field
<% ArticleID = 123 %>
Text field
<% ArticleID = "123" %>

In both cases in the head or body section Before your include page




| Thank you for answering Question #1 Stefan...I'm halfway there!
|
| You said, "in the top of each unique static page (not your include page)
| declare a ASP variable for your include page to use say <% ArticleID=123 %>".
| This sounds perfect! So is this the full code:
| <% ArticleID=123 %>
| or is additional code necessary to declare a variable? Also, does this go
| in <head> or <body>?
|
| Now that the page knows what article it is displaying, let's move on to
| question #2 from my previous post. What syntax do I enter in the DBR Wizard
| to refer to this variable?
|
| We're almost there!
|
| Thanks again, Max
 
K

Kathleen Anderson [MVP - FrontPage]

Max123 said:
Hi Kathleen,

There could be several ways to get to an article page:
- Click a link on the home page
- Click a link on a page that lists all articles
- Click a link in an email
- Click a link on a related article page
- Enter the URL in a browser

The article page filename URLs are hardcoded to the article, for example:
/articles/A1234.asp

It would be really cool if some code on the page could derive the article
ID
from the filename. The (five-character) article ID is always the page's
file
name (without the ".asp" extension). If this is not possible, I am okay
with
manually declaring a variable (a method Stefan discusses in a thread
parallel
to this one).

Do you know of a web resource that shows example code for simple functions
such as:
- Declare a variable
- Manipulate a variable
- Populate a variable with the URL of the current page
- Etc.

I have used databases and query strings extensively and found that they
usually satisfy my needs. But in this one case (multiple static html
pages
with a common DBR region) they don't seem appropriate so I am looking for
a
solution which requires a bit of code.

Thank you, Max

Max:

First, please include the message you are replying to so that everyone can
follow the conversation.

Second, when you say multiple static pages, do you mean that the content of
every page is the same except the info that is specific to each author?


--

~ Kathleen Anderson
Microsoft MVP - FrontPage
Spider Web Woman Designs
web: http://www.spiderwebwoman.com/resources/
 
M

Max123

Okay, I've declared the variable in the BODY thusly:
<% ArticleID = "HT1005" %>

Now it just remains to reference the variable in the DBRW criteria.
I tried several different ways to enter the criteria in the "Value" field:
ArticleID
[ArticleID]
<%("ArticleID")%>
<%[ArticleID]%>
<%ArticleID%>

None of them worked ("No records returned"). Can you please recommend a
syntax to use in the DBRW for referencing a page variable? There must be
some way to tell FrontPage that the criteria is a declared page variable, not
a text string or form field.

Thank you, Max
 
M

Max123

Hi Kathleen,

Thanks for your continued assistance. Stefan B Rusynko was one response
away from a total solution and I'm hoping you can help finish this off.

All I need to know at this point is what to type into the Value field of the
database results wizard to refer to the variable that was declared on the
page.

I've declared the variable in the BODY thusly:
<% ArticleID = "HT1005" %>

I tried several different ways to enter the criteria in the DRW "Value" field:
ArticleID
[ArticleID]
<%("ArticleID")%>
<%[ArticleID]%>
<%ArticleID%>
but none of them worked ("No records returned"). Can you please recommend a
syntax to use in the DRW for referencing a page variable? There must be
some way to tell FrontPage that the criteria is a declared page variable, not
a text string or form field.

Thank you again, Max
 
K

Kathleen Anderson [MVP - FrontPage]

Max:
Please forgive me, but I don't understand the point of what you are trying
to do. If you are willing to declare the variable in the body, why can't you
just hard code it into the Select statement?

--

~ Kathleen Anderson
Microsoft MVP - FrontPage
Spider Web Woman Designs
web: http://www.spiderwebwoman.com/resources/
 
M

Max123

Hi Kathleen,

Well, your question is perfectly valid. And the reason why I cannot do what
you suggest is because the database results area is in an include page. This
include page appears on many article pages, each having different content.

Setting aside for a moment the possibility that I am going about this all
wrong, perhaps you would be kind enough to answer the question that I posed:
how do you reference a page variable in the "Value" field of the Database
Results Wizard?

If you do not know the answer, please let me know that too. Once I find the
answer and my page is working, I will be happy to give a full description of
my site functionity and we can determine if there is a significantly better
way of accomplishing what I'm doing (which I'm hoping is unlikely since I've
been using FrontPage for 7+ years).

Kind regards, Max
 
K

Kathleen Anderson [MVP - FrontPage]

Max:
I do not know the answer to your question. It worked on this today for about
an hour and could not get it to work.
 
M

Max123

Hi Kathleen,

Thank you for your reply. I deeply appreciate your help and the time you
took to find a resolution. If I learn of a solution, I'll post it here.

Kind Regards, Max
 
S

Stefan B Rusynko

The solution is at
http://home.att.net/~codelibrary/FrontPage/tweaks.htm#Link
- as modified below

If you modify your fpdbrgn1.inc to add the line
if len(Request.QueryString(fp_sField)) = 0 then fp_sValue = Session(fp_sField)
After around lines 124/125 and the current code as
fp_sValue = Request.Form(fp_sField)
if len(fp_sValue) = 0 then fp_sValue = Request.QueryString(fp_sField)
if len(Request.QueryString(fp_sField)) = 0 then fp_sValue = Session(fp_sField) ' New Line Added

NOTE: any time you add new DBRW you may need to re-edit fpdbrgn1.inc


That means if FP finds an empty value in a Form field it next looks for something in a query string (w/ a length >0) in a query
string being passed to it.
And w/ the above change (Session now added)
- if it finds neither, it will look for a Session value by that name
You can then just set your page variable (above the HEAD section in the page) as say:
<% Session("ArticleID") = "HT1005" %>

And the use ArticleID session variable in your custom DBRW query (for the DB field also named ArticleID) as say:
SELECT * FROM TableName WHERE ArticleID = '::ArticleID::'

To get the ArticleID (page filename w/o an extension) from the page URL of the article
- where say you have a file structure like :
/articles/HT1005.asp or http://somepath/some folder/HT1005.asp

<%
strURL = Request.ServerVariables("SCRIPT_NAME")
' get the page URL where the script is being run
strFilePart = InStrRev(strURL,"/")+1
' find the location of the last / in the URL
strPage = Mid(strURL,strFilePart,Len(strURL)-strFilePart+1)
' break out just the page filename from the URL
strArticle = Replace(strPage,".asp","")
' clear the extension part of the page filename
Session("ArticleID") = strArticle
' will give you HT1005 from a page like /articles/HT1005.asp
%>


ENJOY



| Hi Kathleen,
|
| Thank you for your reply. I deeply appreciate your help and the time you
| took to find a resolution. If I learn of a solution, I'll post it here.
|
| Kind Regards, Max
 
S

Stefan B Rusynko

PS

Also not a bad idea to clean up any unneeded Session variables at the end of the page by using:

<% Session.Contents.Remove("ArticleID") %>



| The solution is at
| http://home.att.net/~codelibrary/FrontPage/tweaks.htm#Link
| - as modified below
|
| If you modify your fpdbrgn1.inc to add the line
| if len(Request.QueryString(fp_sField)) = 0 then fp_sValue = Session(fp_sField)
| After around lines 124/125 and the current code as
| fp_sValue = Request.Form(fp_sField)
| if len(fp_sValue) = 0 then fp_sValue = Request.QueryString(fp_sField)
| if len(Request.QueryString(fp_sField)) = 0 then fp_sValue = Session(fp_sField) ' New Line Added
|
| NOTE: any time you add new DBRW you may need to re-edit fpdbrgn1.inc
|
|
| That means if FP finds an empty value in a Form field it next looks for something in a query string (w/ a length >0) in a query
| string being passed to it.
| And w/ the above change (Session now added)
| - if it finds neither, it will look for a Session value by that name
| You can then just set your page variable (above the HEAD section in the page) as say:
| <% Session("ArticleID") = "HT1005" %>
|
| And the use ArticleID session variable in your custom DBRW query (for the DB field also named ArticleID) as say:
| SELECT * FROM TableName WHERE ArticleID = '::ArticleID::'
|
| To get the ArticleID (page filename w/o an extension) from the page URL of the article
| - where say you have a file structure like :
| /articles/HT1005.asp or http://somepath/some folder/HT1005.asp
|
| <%
| strURL = Request.ServerVariables("SCRIPT_NAME")
| ' get the page URL where the script is being run
| strFilePart = InStrRev(strURL,"/")+1
| ' find the location of the last / in the URL
| strPage = Mid(strURL,strFilePart,Len(strURL)-strFilePart+1)
| ' break out just the page filename from the URL
| strArticle = Replace(strPage,".asp","")
| ' clear the extension part of the page filename
| Session("ArticleID") = strArticle
| ' will give you HT1005 from a page like /articles/HT1005.asp
| %>
|
|
| ENJOY
| --
|
| _____________________________________________
| SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
| "Warning - Using the F1 Key will not break anything!" (-;
| To find the best Newsgroup for FrontPage support see:
| http://www.net-sites.com/sitebuilder/newsgroups.asp
| _____________________________________________
|
|
|| Hi Kathleen,
||
|| Thank you for your reply. I deeply appreciate your help and the time you
|| took to find a resolution. If I learn of a solution, I'll post it here.
||
|| Kind Regards, Max
|
|
 

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