Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view 10 records per page

Status
Not open for further replies.

QTip

Programmer
Mar 7, 2001
66
0
0
BE
Hello,

this is the situation: I have a sort of text file with an unknown amount of data. This data has delimiters. ex: dkmqlsgfkjqsldfj|lqkjqslkfj|lksdjf|lkjslkfjlq|.
Now I show them on the screen like this:
dkmqlsgfkjqsldfj
lqkjqslkfj
lksdjf
lkjslkfjlq

ok for now, but I want to show the first 10 lines and then have a link "next" to show next 10, and so on...

How can I do this?

Thanks in advance!
 
yes I know.
I know how it works with recordsets and database stuff. But I'm not reading from a database. I'm reading from a sort of txt file where all the data is kept on one line. The "|" is the line delimiter.

I know the URL you gave me, but that's all with recordsets and database... and I'm not using that...

Are there other possibilities without any recordset or database stuff?
The reason why I don't use any database is because I get records from the AS/400 (i-series) via an rpg program and not via sql or odbc because that's too slow.

Anyone got an idea? thnx!
 
This a very bad way of doing it with an undeterminable amount of data. This is untested but should work

The only way is to read thru the file each time.
<%
set FSO = server.createObject(&quot;Scripting.FileSystemObject&quot;)
Filepath = Server.MapPath(&quot;file.txt&quot;)
if FSO.FileExists(Filepath) Then
set file = FSO.GetFile(Filepath)
Set TextStream = file.OpenAsTextStream(1,-2)
tempStr = TextStream.ReadAll
Set TextStream = nothing
Else
Response.Write &quot;File Not Found&quot;
End If
Set FSO = Nothing

newArray=split(tempStr,&quot;|&quot;)
lowerIndex=request(&quot;index&quot;) ' passed when they click next
upperIndex=tempIndex+10
if upperIndex>ubound(newArray) then upperIndex=ubound(newArray)

for count=lowerIndex to upperIndex
response.write newArray(count) & &quot;<BR>&quot;
next

%>

 
Hi GaryC132, thnx for your reply. I may have explained it wrong. I get the data directly from AS/400 into a string. I don't read the data from a file. Sorry for the bad explination.

I have one way that works.
Right now I get a certain amout of data into a string, I start cutting the string, when I have 10 &quot;records&quot; to show, I stop the cutting and I delete the characters I displayed from the original string. So next page gets a new string where the origingal string is a little shorter because the data that is already displayed is not in the string anymore.

... not the best way to work... but it works for now. Does anybody know a more stable way to work?

Thnx for the effort!
 
Use GaryC132's system of splitting your | delimited string into an array (newArray=split(tempStr,&quot;|&quot;))

Then you can just for loop from currentRecord to currentRecord + 10. Next page sets currentRecord = currentRecord + 10 and re-does the loop. Previous page sets it back -10. GaryC132's code may be actually doing this, sort of.

This may be fairly similar to above:
Code:
<%
dim yourDataString 'you get this from DB instead
yourDataString = &quot;rec1|rec2|rec3|rec4|rec5|rec6|rec7|rec8|rec9|rec10|rec11|&quot;

dim arrData
arrData = split(yourDataString, &quot;|&quot;)

dim currentRec, recsPerPage, n
currentRec = 0 'or CInt(Request(&quot;newRec&quot;)) or whatever
recsPerPage = 5

for n = currentRec to currentRec + recsPerPage
  response.write(arrData(n) & &quot;<br>&quot;)
next

'link for prev & next
%>
<a href=&quot;thispage.asp?newRec=<%=currentRec-5%>&quot;>Previous</a>
<a href=&quot;thispage.asp?newRec=<%=currentRec+5%>&quot;>Next</a>
You can probably go from that.

And finally, as the string gets bigger performance will drop to the point that a recordset into the DB would be much quicker.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Yes I can try that. But it are a lot of records I have, almost 30000. Wouldn't that be to big to use in a array?

Let me know what you think! If the performance is good for that kind of array then it's a good solution.

Thnx for the reply!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top