PDA

View Full Version : About Paging


anandc
10-06-2002, 08:06 PM
Hi every body


I am coding for a website. the DB is access 2k with hundreds of records. the user will search as per his/her need and the result will be again number of records.
What i want is DB Paging. I dont have any idea how to do this
pls help me....

Anand

BigDaddy
10-06-2002, 11:40 PM
Check this out:

http://www.asp101.com/samples/db_paging.asp

whammy
10-07-2002, 12:44 AM
I don't think I could find a better example... the code is pretty nice too...

glenngv
10-07-2002, 04:57 AM
Originally posted by whammy
I don't think I could find a better example... the code is pretty nice too...

except that it does not check for non-numeric value in the querystring which would happen if the user would try to modify it.

If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If

it could have been:

If isNumeric(Request.QueryString("page")) Then
iPageCurrent = CInt(Request.QueryString("page"))
Else
iPageCurrent = 1
End If

whammy
10-07-2002, 01:16 PM
Good catch. :D

I just stripped anything but numbers in my querystring (in my latest experiment) so if someone modifies it it won't throw an error - I thought about checking IsNumeric() but to me this is simpler:


Function ExtractNumbers(str) '''''''''''''''''''''
If IsNull(str) Then str = ""
Dim enRegEx
Set enRegEx = New RegExp
enRegEx.Pattern = "\D"
enRegEx.Global = True
ExtractNumbers = enRegEx.Replace(str,"")
End Function '''''''''''''''''''''''''''''''''''''

'.................more stuff here

sid = ExtractNumbers(Request.QueryString("sid"))
If sid = "" Then Response.Redirect("displayscript.asp?sid=0")


Since I already have the ExtractNumbers function on the page I figured that's a good a place as any to use it. I don't need to convert the sid into an integer in this case (just treat it like one in the SQL statement, since I'm only using it to match the sid in the db).

Besides, wouldn't 2.5 also match IsNumeric() - not sure if it would throw an error or not, but probably would if you were requesting from a field that wasn't a float?

:)

aCcodeMonkey
10-07-2002, 09:38 PM
anandc,
Question..
What is the browser that the target user will be using?
If the targeted user is only going to be using IE. You can use a mix of ASP and IE's integrated data binding services to "Page" thru long recordsets.

Here is an example fo how I use the two services together.
Data Banding Example (http://www.thinkhdi.com/chapters/cos/HDI_template4/webdata/ExampleRemoteData.asp)

NOTE: The database is set for read only as the example sits on a website template.


Here is a good article that does not require the use of query strings to set to page thru a recordset.
Recordset Paging with ADO 2.0 (http://www.asp101.com/articles/recordsetpaging/index.asp)

glenngv
10-08-2002, 02:01 AM
Originally posted by whammy

Besides, wouldn't 2.5 also match IsNumeric() - not sure if it would throw an error or not, but probably would if you were requesting from a field that wasn't a float?

:)

yes, but CInt will convert it to the variant of subtype Integer, making 2.5 become 2 :)

If isNumeric(Request.QueryString("page")) Then
iPageCurrent = CInt(Request.QueryString("page"))
Else
iPageCurrent = 1
End If

whammy
10-08-2002, 02:17 AM
Yup... but if you try to use CInt("blah") it returns:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CInt'

/datatype.asp, line 1


Which is why I think my solution is a lot simpler, since you just eliminate anything that is not a digit...

At least, it's a lot easier to use a function using a regular expression than it is to compare a couple of datatypes... and probably less code, as shown above.

glenngv
10-08-2002, 02:56 AM
it wouldn't Cint "blah" in this code if the page querystring value is "blah", would it?


If isNumeric(Request.QueryString("page")) Then
iPageCurrent = CInt(Request.QueryString("page"))
Else
iPageCurrent = 1
End If

whammy
10-08-2002, 02:57 AM
No, but that might be a bit more code that what I used, considering the overall scripting... :D

They are both fine... just a couple of different ways of preventing errors, IMHO. I just like to keep it simple... if I know I'm looking for a number in the querystring, I make sure it's a number and nothing else.

Otherwise you have to check all kinds of junk to make sure it doesn't throw an error (in an Access database, anyway), like "[]'", and of course that depends on the datatype of the field...

anandc
10-08-2002, 06:19 AM
Hi evrybody

Thks a lot for ur help

Anand

glenngv
10-08-2002, 07:10 AM
Originally posted by whammy
No, but that might be a bit more code that what I used, considering the overall scripting... :D

They are both fine... just a couple of different ways of preventing errors, IMHO. I just like to keep it simple... if I know I'm looking for a number in the querystring, I make sure it's a number and nothing else.

Otherwise you have to check all kinds of junk to make sure it doesn't throw an error (in an Access database, anyway), like "[]'", and of course that depends on the datatype of the field...


Function GetNumber(str,default)
if isNumeric(str) then GetNumber=CInt(str) else GetNumber=default
End Function

iPageCurrent = GetNumber(Request.QueryString("page"),1)


:)

whammy
10-08-2002, 04:24 PM
That is probably about what I would use, too -

Function GetNumber(str)
If IsNumeric(str) Then GetNumber=CInt(str) Else GetNumber=0
End Function

iPageCurrent = GetNumber(Request.QueryString("page"),1)


... if I didn't also have other uses for the ExtractNumber function (since I plan to use it in an include file on multiple pages along with a handful of other really handy functions - for instance to strip non-digits from phone numbers, etc.).

:)

glenngv
10-09-2002, 02:21 AM
it is more generic if it has a specified default value :)


Function GetNumber(str,defaultValue)
if isNumeric(str) then GetNumber=CInt(str) else GetNumber=defaultValue
End Function

iPageCurrent = GetNumber(Request.QueryString("page"),1)
iAnotherNumber = GetNumber(Request.QueryString("num"),0)

whammy
10-09-2002, 02:29 AM
True, true. Actually I have some functions that work like that. :)