How to display custom results from a database field

J

John

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
 
T

Trevor L.

John said:
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/
----------------------------------------
 
J

John

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. said:
John said:
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 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/
----------------------------------------
 
T

Trevor L.

John said:
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/
----------------------------------------
 
J

John

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. said:
John said:
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/
 
T

Trevor L.

John said:
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/
----------------------------------------
 
T

Trevor L.

Trevor said:
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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/
----------------------------------------
 
S

Stefan B Rusynko

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!" (-;
_____________________________________________


| 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/
| ----------------------------------------
 
J

John

thanks, I tried the other solution. This one would probably work to

Trevor L. said:
Trevor said:
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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 = "&nbsp;"
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/
 

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