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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed with asp code

Status
Not open for further replies.

fireburner69

Programmer
Aug 22, 2002
108
GR
This is the code witch i use in order to make a news page

I wanted to show in each page only 7 news and when the number goes more than 7 to go to the next page!

I have managed to make new page and so on but still in the first page shows all the news!

I the second page shows from the 8 and so on!

Any ideas why this is happening?


check the code!

<%

Dim nPage, nItems
'Collects Page References
nPage = request(&quot;p&quot;)



'No Page reference taken then default to first page
if isnumeric(nPage) and nPage <> &quot;&quot; then
if nPage > 0 then
nPage = cint(nPage)
else
nPage = 1
end if
else
nPage = 1
end if

'How many items to display per page
nItems = 7

' Define variants
Dim numID, strTitle, strStory, strLink, strSubmittedBy, strDatestamp, adOpenStatic, adLockReadOnly, adCmdTable, numCounter
adOpenStatic = 1
adLockReadOnly = 1
adCmdTable = 2


' Define database file type and location
Dim objConn, objRS, nRecordCount, nPageCount, nPageSize, sPrev, sNext
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

objConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=\\athcfs01.hosting.forth\virtual\speftp\db\news.mdb;&quot; & _
&quot;Persist Security Info=False&quot;


' Open News table in database
objRS.Open &quot;News&quot;, objConn, adOpenStatic, adLockReadOnly, adCmdTable

' Open News table in database
' objRS.Open sSQL, objConn, adOpenStatic, adLockReadOnly, adCmdTable

objRS.cachesize= 3
objRS.PageSize = nItems

nRecordCount = objRS.RecordCount
nPageCount = objRS.PageCount
nPageSize = objRS.PageSize

if Cint(nPage) <= Cint(nPageCount) then
nPage = nPage
else
nPage = nPageCount
end if

objRS.AbsolutePage = nPage

' Create the navi
if Cint(nPage) = Cint(1) or Cint(nPage) = 0 then
sPrev = &quot;<< Prev&quot;
Else
sPrev = &quot;<a href=&quot;&quot;table.asp?p=&quot; & (nPage - 1) & &quot;&quot;&quot;><< Prev</a>&quot;
End if
if Cint(nPage) = Cint(nPageCount) then
sNext = &quot;Next >>&quot;
Else
sNext = &quot;<a href=&quot;&quot;table.asp?p=&quot; & (nPage + 1) & &quot;&quot;&quot;>Next >></a>&quot;
End if

if not objRS.eof then
' Display the Navi
response.write(sPrev & &quot; | <b>&quot; & nPage & &quot;</b> of &quot; & nPageCount & &quot; | &quot; & sNext)

'Display the data
Do until objRS.eof
response.Write(&quot;<p>&quot;)
if objRS(&quot;Link&quot;) <> &quot; &quot; then
response.write(&quot;<img src='linkicon.gif'> &quot;)
End If
response.Write(&quot;<a href='showstory.asp?storyid=&quot; & objRS(&quot;ID&quot;) & &quot;'>&quot;)
response.Write(objRS(&quot;Title&quot;) & &quot;</a>&quot;)
response.Write(&quot;<br><small>&quot; & objRS(&quot;Datestamp&quot;) & &quot;</small><br><br>&quot;)
response.Write(&quot;</font></p>&quot;)
objRS.MoveNext
Loop
Else
response.write(&quot;No Records&quot;)
End if

' Close & clean up
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>


thanx for your time!

:)
 
Why dont you add a counter inside the Do loop and exit do when the counter reachs 7?

///edox
..
 
The code that made tha jop is these one :

<%

Dim nPage, nItems
'Collects Page References
nPage = request(&quot;p&quot;)



'No Page reference taken then default to first page
if isnumeric(nPage) and nPage <> &quot;&quot; then
if nPage > 0 then
nPage = cint(nPage)
else
nPage = 1
end if
else
nPage = 1
end if

'How many items to display per page
nItems = 7

' Define variants
Dim numID, strTitle, strStory, strLink, strSubmittedBy, strDatestamp, adOpenStatic, adLockReadOnly, adCmdTable, numCounter
adOpenStatic = 1
adLockReadOnly = 1
adCmdTable = 2


' Define database file type and location
Dim objConn, objRS, nRecordCount, nPageCount, nPageSize, sPrev, sNext
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

objConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=\\athcfs01.hosting.forth\virtual\speftp\db\news.mdb;&quot; & _
&quot;Persist Security Info=False&quot;


' Open News table in database
objRS.Open &quot;News&quot;, objConn, adOpenStatic, adLockReadOnly, adCmdTable


objRS.cachesize= 3
objRS.PageSize = nItems

nRecordCount = objRS.RecordCount
nPageCount = objRS.PageCount
nPageSize = objRS.PageSize

if Cint(nPage) <= Cint(nPageCount) then
nPage = nPage
else
nPage = nPageCount
end if

objRS.AbsolutePage = nPage

' Create the navi
if Cint(nPage) = Cint(1) or Cint(nPage) = 0 then
sPrev = &quot;<< Prev&quot;
Else
sPrev = &quot;<a href=&quot;&quot;table2.asp?p=&quot; & (nPage - 1) & &quot;&quot;&quot;><< Prev</a>&quot;
End if
if Cint(nPage) = Cint(nPageCount) then
sNext = &quot;Next >>&quot;
Else
sNext = &quot;<a href=&quot;&quot;table2.asp?p=&quot; & (nPage + 1) & &quot;&quot;&quot;>Next >></a>&quot;
End if

'if not objRS.eof then
' Display the Navi
response.write(sPrev & &quot; | <b>&quot; & nPage & &quot;</b> of &quot; & nPageCount & &quot; | &quot; & sNext)

'Display the data

if not objRS.bof then
nRecordCount = 0
Do While Not objRS.eof and nRecordCount < nPageSize

'Do until objRS.eof
response.Write(&quot;<p>&quot;)
if objRS(&quot;Link&quot;) <> &quot; &quot; then
response.write(&quot;<img src='linkicon.gif'> &quot;)
End If
response.Write(&quot;<a href='showstory.asp?storyid=&quot; & objRS(&quot;ID&quot;) & &quot;'>&quot;)
response.Write(objRS(&quot;Title&quot;) & &quot;</a>&quot;)
response.Write(&quot;<br><small>&quot; & objRS(&quot;Datestamp&quot;) & &quot;</small><br><br>&quot;)
response.Write(&quot;</font></p>&quot;)
' objRS.MoveNext

' Do While Not objRS.eof and nRecordCount < nPageSize
nRecordCount = nRecordCount + 1
objRS.MoveNext
loop




Else
response.write(&quot;No Records&quot;)
End if

' Close & clean up
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>




Thanx to all for your help! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top