This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > FrontPage Programming > February 2007 > How to display custom results from a database field
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to display custom results from a database field
|
|
|
| I have a Access database and one of the field is Number
It can be 1,2 3, etc..
However when I display the database on a Web page I need to replace the
number with somethign like this
'1 item' , '2 items' '3 items', etc.
As far as I know I need to modifyf pdblib.inc but I have no idea how to do
it
ANy help would be appreciated
TIA
| |
| Trevor L. 2007-02-09, 3:17 am |
| John wrote:
> I have a Access database and one of the field is Number
>
> It can be 1,2 3, etc..
>
> However when I display the database on a Web page I need to replace
> the number with somethign like this
>
> '1 item' , '2 items' '3 items', etc.
>
> As far as I know I need to modifyf pdblib.inc but I have no idea how
> to do it
>
> ANy help would be appreciated
Why not use a JS function
function display_no(no)
{
var added_text= (no==1) ? ' item' : ' items'
return no + added_text
}
and instead of displaying, say
<%=FP_FieldVal(fp_rs,"name")%>
use
display_no(<%=FP_FieldVal(fp_rs,"name")%> )
Not tested
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
----------------------------------------
| |
|
| OK, but where do I write this function ? In the fpdblib.inc file or do I
need to start a new file ?
in other words how do i tell frontpage that this is a JS function and not
VBScript
"Trevor L." <Trevor_L.@Canberra> wrote in message
news:OzVjz4$SHHA.996@TK2MSFTNGP02.phx.gbl...
> John wrote:
>
>
> Why not use a JS function
>
> function display_no(no)
> {
> var added_text= (no==1) ? ' item' : ' items'
> return no + added_text
> }
>
> and instead of displaying, say <%=FP_FieldVal(fp_rs,"name")%>
> use
> display_no(<%=FP_FieldVal(fp_rs,"name")%> )
>
> Not tested
> --
> Cheers,
> Trevor L.
> [ Microsoft MVP - FrontPage ]
> MVPS Website: http://trevorl.mvps.org/
> ----------------------------------------
| |
| Trevor L. 2007-02-09, 3:17 am |
| John wrote:
> OK, but where do I write this function ? In the fpdblib.inc file or
> do I need to start a new file ?
>
> in other words how do i tell frontpage that this is a JS function and
> not VBScript
As I wrote, I haven't tested this, but in your .html page (or .asp page),
add this in your <head> section:
<script type="text/javascript">
function display_no(no)
{
var added_text = (no==1) ? ' item' : ' items'
return no + added_text
}
</script>
Alternatively, as you suggest, start a new file, say scripts/external.js and
put this into it:
function display_no(no)
{
var added_text= (no==1) ? ' item' : ' items'
return no + added_text
}
Then, add this in the <head> section:
<script type="text/javascript" src="scripts/external.js"></script>
This will run on the client, not on the server. The type declaration says it
is JavaScript
If this doesn't work, I had better test it myself
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
----------------------------------------
| |
|
|
ok, i did it as you suggested in the head section of asp page and this is
what get's dispayed on the Web page
display_no(2)
display_no(1)
display_no(3)
etc...
"Trevor L." <Trevor_L.@Canberra> wrote in message
news:uOJ%23YjATHHA.4956@TK2MSFTNGP04.phx.gbl...
> John wrote:
>
> As I wrote, I haven't tested this, but in your .html page (or .asp page),
> add this in your <head> section:
> <script type="text/javascript">
> function display_no(no)
> {
> var added_text = (no==1) ? ' item' : ' items'
> return no + added_text
> }
> </script>
>
> Alternatively, as you suggest, start a new file, say scripts/external.js
> and put this into it:
> function display_no(no)
> {
> var added_text= (no==1) ? ' item' : ' items'
> return no + added_text
> }
>
> Then, add this in the <head> section:
> <script type="text/javascript" src="scripts/external.js"></script>
>
> This will run on the client, not on the server. The type declaration says
> it is JavaScript
>
> If this doesn't work, I had better test it myself
> --
> Cheers,
> Trevor L.
> [ Microsoft MVP - FrontPage ]
> MVPS Website: http://trevorl.mvps.org/
> ----------------------------------------
>
| |
| Trevor L. 2007-02-09, 3:17 am |
| John wrote:
> ok, i did it as you suggested in the head section of asp page and
> this is what get's dispayed on the Web page
>
> display_no(2)
> display_no(1)
> display_no(3)
Sorry about that.
Time for me do the testing
IGBTY (I'll get back to you)
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
----------------------------------------
| |
| Trevor L. 2007-02-09, 3:17 am |
| Trevor L. wrote:
> John wrote:
>
> Sorry about that.
>
> Time for me do the testing
>
> IGBTY (I'll get back to you)
Yes, well, the behaviour you saw is because display_no() was read as HTML
whereas it should be a call to JS, i.e. it doesn't belong there.
My mistake for not thinking it through and testing before I posted.
I thought of a couple of solutions
One is to just the add the text " items" after the database field
e.g. change <td valign="top"><%=FP_FieldVal(fp_rs,"item_count")%></td>
to <td valign="top"><%=FP_FieldVal(fp_rs,"item_count")%> items</td>
This doesn't test for only one item, so this will read "1 items" when the
item count is 1
The other is to alter the VBScript function FP_FieldVal to add the text
"item" or " items"
This is the function in fpdblib
Function FP_FieldVal(rs, fldname)
FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
if FP_FieldVal = "" then FP_FieldVal = " "
End Function
Change it to
Function FP_FieldVal(rs, fldname)
FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname)) & " items"
if FP_FieldVal = "" then FP_FieldVal = " "
End Function
This needs a bit of fine tuning
1. You only want to use it when the field is item_count (or whatever)
So try
Function FP_FieldVal(rs, fldname)
FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
if fldname = "item_count" then
FP_FieldVal = FP_FieldVal + " items"
end if
if FP_FieldVal = "" then FP_FieldVal = " "
End Function
2. You want to test for item_count = 1
So try
Function FP_FieldVal(rs, fldname)
FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
if fldname = "item_count" then
if FP_FieldVal = "1" then
FP_FieldVal = FP_FieldVal + " item"
else
FP_FieldVal = FP_FieldVal + " items"
end if
end if
if FP_FieldVal = "" then FP_FieldVal = " "
End Function
This has a problem in that item_count is probably numeric, so the test if
FP_FieldVal = "1" will fail with a field type mismatch error
So try
Function FP_FieldVal(rs, fldname)
FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
if fldname = "item_count" then
if CStr(FP_FieldVal) = "1" then
FP_FieldVal = FP_FieldVal + " item"
else
FP_FieldVal = FP_FieldVal + " items"
end if
end if
if FP_FieldVal = "" then FP_FieldVal = " "
End Function
I haven't tested this because the fields I am trying to test against are all
character to start with.
I still think a JS solution would work, but if you can get this to work,
then let's leave well enough alone
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
----------------------------------------
| |
| Stefan B Rusynko 2007-02-09, 6:15 am |
| If the DB value is comes from
<%=FP_FieldVal(fp_rs,"name")%>
Then to display that w/ a text string after it just change the server side code to
<%=FP_FieldVal(fp_rs,"name") & " item"%>
And if you want the text to change depending on the value
<% IF FP_FieldVal(fp_rs,"name")=1 THEN %>
<%=FP_FieldVal(fp_rs,"name") & " item"%>
<% ELSE %>
<%=FP_FieldVal(fp_rs,"name") & " items"%>
<% END IF %>
--
_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________
"Trevor L." <Trevor_L.@Canberra> wrote in message news:OzVjz4$SHHA.996@TK2MSFTNGP02.phx.gbl...
| John wrote:
| > I have a Access database and one of the field is Number
| >
| > It can be 1,2 3, etc..
| >
| > However when I display the database on a Web page I need to replace
| > the number with somethign like this
| >
| > '1 item' , '2 items' '3 items', etc.
| >
| > As far as I know I need to modifyf pdblib.inc but I have no idea how
| > to do it
| >
| > ANy help would be appreciated
|
|
| Why not use a JS function
|
| function display_no(no)
| {
| var added_text= (no==1) ? ' item' : ' items'
| return no + added_text
| }
|
| and instead of displaying, say
| <%=FP_FieldVal(fp_rs,"name")%>
| use
| display_no(<%=FP_FieldVal(fp_rs,"name")%> )
|
| Not tested
| --
| Cheers,
| Trevor L.
| [ Microsoft MVP - FrontPage ]
| MVPS Website: http://trevorl.mvps.org/
| ----------------------------------------
| |
|
| thanks a lot, this works
"Stefan B Rusynko" <sbr_enjoy@hotmail.com> wrote in message
news:Ox$6buCTHHA.192@TK2MSFTNGP04.phx.gbl...
> If the DB value is comes from
> <%=FP_FieldVal(fp_rs,"name")%>
> Then to display that w/ a text string after it just change the server side
> code to
> <%=FP_FieldVal(fp_rs,"name") & " item"%>
>
> And if you want the text to change depending on the value
>
> <% IF FP_FieldVal(fp_rs,"name")=1 THEN %>
> <%=FP_FieldVal(fp_rs,"name") & " item"%>
> <% ELSE %>
> <%=FP_FieldVal(fp_rs,"name") & " items"%>
>
> <% END IF %>
> --
>
> _____________________________________________
> SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
> "Warning - Using the F1 Key will not break anything!" (-;
> _____________________________________________
>
>
> "Trevor L." <Trevor_L.@Canberra> wrote in message
> news:OzVjz4$SHHA.996@TK2MSFTNGP02.phx.gbl...
> | John wrote:
> | > I have a Access database and one of the field is Number
> | >
> | > It can be 1,2 3, etc..
> | >
> | > However when I display the database on a Web page I need to replace
> | > the number with somethign like this
> | >
> | > '1 item' , '2 items' '3 items', etc.
> | >
> | > As far as I know I need to modifyf pdblib.inc but I have no idea how
> | > to do it
> | >
> | > ANy help would be appreciated
> |
> |
> | Why not use a JS function
> |
> | function display_no(no)
> | {
> | var added_text= (no==1) ? ' item' : ' items'
> | return no + added_text
> | }
> |
> | and instead of displaying, say
> | <%=FP_FieldVal(fp_rs,"name")%>
> | use
> | display_no(<%=FP_FieldVal(fp_rs,"name")%> )
> |
> | Not tested
> | --
> | Cheers,
> | Trevor L.
> | [ Microsoft MVP - FrontPage ]
> | MVPS Website: http://trevorl.mvps.org/
> | ----------------------------------------
>
>
| |
|
| thanks, I tried the other solution. This one would probably work to
"Trevor L." <Trevor_L.@Canberra> wrote in message
news:uPFOKPBTHHA.4276@TK2MSFTNGP02.phx.gbl...
> Trevor L. wrote:
>
> Yes, well, the behaviour you saw is because display_no() was read as HTML
> whereas it should be a call to JS, i.e. it doesn't belong there.
> My mistake for not thinking it through and testing before I posted.
>
> I thought of a couple of solutions
>
> One is to just the add the text " items" after the database field
> e.g. change <td valign="top"><%=FP_FieldVal(fp_rs,"item_count")%></td>
> to <td valign="top"><%=FP_FieldVal(fp_rs,"item_count")%> items</td>
> This doesn't test for only one item, so this will read "1 items" when the
> item count is 1
>
> The other is to alter the VBScript function FP_FieldVal to add the text
> "item" or " items"
>
> This is the function in fpdblib
> Function FP_FieldVal(rs, fldname)
> FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
> if FP_FieldVal = "" then FP_FieldVal = " "
> End Function
>
> Change it to
> Function FP_FieldVal(rs, fldname)
> FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname)) & " items"
> if FP_FieldVal = "" then FP_FieldVal = " "
> End Function
>
> This needs a bit of fine tuning
>
> 1. You only want to use it when the field is item_count (or whatever)
> So try
> Function FP_FieldVal(rs, fldname)
> FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
> if fldname = "item_count" then
> FP_FieldVal = FP_FieldVal + " items"
> end if
> if FP_FieldVal = "" then FP_FieldVal = " "
> End Function
> 2. You want to test for item_count = 1
> So try
> Function FP_FieldVal(rs, fldname)
> FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
> if fldname = "item_count" then
> if FP_FieldVal = "1" then
> FP_FieldVal = FP_FieldVal + " item"
> else
> FP_FieldVal = FP_FieldVal + " items"
> end if
> end if
> if FP_FieldVal = "" then FP_FieldVal = " "
> End Function
> This has a problem in that item_count is probably numeric, so the test if
> FP_FieldVal = "1" will fail with a field type mismatch error
>
> So try
> Function FP_FieldVal(rs, fldname)
> FP_FieldVal = FP_HTMLEncode(FP_Field(rs, fldname))
> if fldname = "item_count" then
> if CStr(FP_FieldVal) = "1" then
> FP_FieldVal = FP_FieldVal + " item"
> else
> FP_FieldVal = FP_FieldVal + " items"
> end if
> end if
> if FP_FieldVal = "" then FP_FieldVal = " "
> End Function
>
> I haven't tested this because the fields I am trying to test against are
> all character to start with.
>
>
> I still think a JS solution would work, but if you can get this to work,
> then let's leave well enough alone
> --
> Cheers,
> Trevor L.
> [ Microsoft MVP - FrontPage ]
> MVPS Website: http://trevorl.mvps.org/
> ----------------------------------------
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|