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

Asp news help

Status
Not open for further replies.

fireburner69

Programmer
Aug 22, 2002
108
GR
I have a asp file that can show some news and i want to make it so when there are more than 7 news posted to make a seperate like below so that each page can show only 7 news! How can ido that?
 
These is the table code!


<%Option Explicit%>
<html>

<head>
<title>ÁÍÁÊÏÉÍÙÓÅÉÓ</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-7&quot;>
</head>
<SCRIPT language=javascript src=&quot;j_scripts/rightclick.js&quot;></SCRIPT>
<STYLE type=text/css>A:link {
COLOR: #00000; TEXT-DECORATION: underline
}
A:visited {
TEXT-DECORATION: underline; color:000000
}
A:active {
TEXT-DECORATION: underline
}
A:hover {
COLOR: #31a2a2; TEXT-DECORATION: underline
}
</STYLE>
<body>
<CENTER><h1><FONT FACE=ARIAL>ÐÉÍÁÊÁÓ ÁÍÁÊÏÉÍÙÓÅÙÍ</FONT></h1></CENTER>

<FONT FACE=ARIAL>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;50%&quot; align=center>
<tr>
<td width=&quot;6&quot; valign=&quot;bottom&quot; align=&quot;left&quot;><img border=&quot;0&quot; src=&quot;storybox-title-left-corner.gif&quot; width=&quot;6&quot; height=&quot;22&quot; nowrap></td>
<td class=&quot;storytitle&quot; width=&quot;45%&quot; background=&quot;storybox-title-bluebg.gif&quot; nowrap>&nbsp;<big><FONT FACE=ARIAL COLOR=WHITE>Êáíôå click ôçí êáèå åðéêåöáëéäá ãéá ðåñéóóïôåñåò ðëçñïöïñéåò</big></td>
<td width=&quot;50%&quot; background=&quot;storybox-title-silverbg.gif&quot; nowrap><img border=&quot;0&quot; src=&quot;storybox-title-cascade.gif&quot; width=&quot;43&quot; height=&quot;22&quot; nowrap></td>
<td class=&quot;storytitle&quot; width=&quot;5%&quot; align=&quot;right&quot; background=&quot;storybox-title-silverbg.gif&quot; nowrap></td>
<td width=&quot;6&quot; valign=&quot;bottom&quot; align=&quot;left&quot;><img border=&quot;0&quot; src=&quot;storybox-title-right-corner.gif&quot; width=&quot;6&quot; height=&quot;22&quot;></td>
</tr>
<tr>
<td width=&quot;6&quot; background=&quot;storybox-left-tube-bg.gif&quot; valign=&quot;top&quot; align=&quot;left&quot;><img border=&quot;0&quot; src=&quot;storybox-left-tube-bg.gif&quot; width=&quot;6&quot; height=&quot;5&quot;></td>
<td class=&quot;storybox&quot; colspan=&quot;3&quot;><table border=&quot;0&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;><td width=&quot;100%&quot;></td></tr>
</table>
<table border=&quot;0&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td align=&quot;center&quot;>
</td><br>
<tr>
<td align=&quot;center&quot;>
<span class=&quot;storybyline&quot;>

<%

' 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
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

' Move to the last record
objRS.MoveLast

' Write the headlines and dates to the page
Response.Write &quot;<p>&quot;

While Not objRS.BOF
strTitle = objRS(&quot;Title&quot;)
numID = objRS(&quot;ID&quot;)
strLink = objRS(&quot;Link&quot;)
strDatestamp = objRS(&quot;Datestamp&quot;)

if strLink <> &quot; &quot; then
Response.write &quot;<img src='linkicon.gif'>&nbsp;&nbsp;&quot;
End If

Response.Write &quot;<a href='showstory.asp?storyid=&quot; & numID & &quot;'>&quot;
Response.Write strTitle & &quot;</a>&quot;
Response.Write &quot;<br><small>&quot; & strDatestamp & &quot;</small><br><br>&quot;
objRS.MovePrevious
Wend

Response.Write &quot;</font></p>&quot;
' Close & clean up
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing

%>



</span>
</td>
</tr>
</table></td>
<td width=&quot;6&quot; background=&quot;storybox-right-tube-bg.gif&quot;><img border=&quot;0&quot; src=&quot;storybox-right-tube-bg.gif&quot; width=&quot;6&quot; height=&quot;5&quot;></td>
</tr>
<tr>
<td width=&quot;6&quot; valign=&quot;top&quot; align=&quot;left&quot; height=&quot;5&quot;><img border=&quot;0&quot; src=&quot;storybox-bottom-left-corner.gif&quot; width=&quot;6&quot; height=&quot;5&quot;></td>
<td width=&quot;50%&quot; height=&quot;5&quot; background=&quot;storybox-bottom-bluebg.gif&quot;><img border=&quot;0&quot; src=&quot;storybox-bottom-bluebg.gif&quot; width=&quot;10&quot; height=&quot;5&quot;></td>
<td width=&quot;50%&quot; height=&quot;5&quot; valign=&quot;top&quot; align=&quot;right&quot; background=&quot;storybox-bottom-bluebg.gif&quot;><img border=&quot;0&quot; src=&quot;storybox-bottom-cascade.gif&quot; width=&quot;23&quot; height=&quot;5&quot;></td>
<td width=&quot;75&quot; height=&quot;5&quot; background=&quot;storybox-bottom-silverbg.gif&quot;><img border=&quot;0&quot; src=&quot;storybox-bottom-silverbg.gif&quot; width=&quot;10&quot; height=&quot;5&quot;></td>
<td width=&quot;6&quot; height=&quot;5&quot;><img border=&quot;0&quot; src=&quot;storybox-bottom-right-corner.gif&quot; width=&quot;6&quot; height=&quot;5&quot;></td>
</tr>
</table>

</BODY>
</HTML>



hope its helpful
 
I hope this works...knowing my quick rushing to get this done i have probably messed it up big style.

<%
'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
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;

' SQL Statement
sSQL = &quot;SELECT news.Title, news.ID, news.Link, news.Datestamp FROM news &quot; & _
&quot;ORDER BY Datestamp DESC;&quot;

' 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;news.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;news.asp?p=&quot; & (nPage + 1) & &quot;&quot;&quot;>Next >></a>&quot;
End if

if not objRecordSet.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
%> - FateFirst
 
Microsoft VBScript runtime error '800a01f4'

Variable is undefined: 'nPage'

/news/table.asp, line 48


this is the error!

But thanx for your time!

How can i overcome this problem!?
 
assuming I have the right line 48,
like so:
Code:
'at top
<%
Dim nPage

'Collects Page References
nPage = request(&quot;p&quot;)
.
.
.
otherwise post the code surrounding that area with note telling which line is 48
-Tarwn
Tada, now it's defined :) ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
ok after some things the code looks like these :
<%

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
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;

' SQL Statement
sSQL = &quot;SELECT news.Title, news.ID, news.Link, news.Datestamp FROM news &quot; & _
&quot;ORDER BY Datestamp DESC;&quot;

' 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;news.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;news.asp?p=&quot; & (nPage + 1) & &quot;&quot;&quot;>Next >></a>&quot;
End if

if not objRecordSet.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
%>


like that the error is that sSQL is not defined!
So i go to these line and add sSQL
->Dim objConn, objRS

and after that!!!!!


an error like these comes along....

Microsoft JET Database Engine error '80040e14'

Syntax error in FROM clause.

/news/table.asp, line 88




line 88:
objRS.Open sSQL, objConn, adOpenStatic, adLockReadOnly, adCmdTable



Thanx again for yout time! :)))))
 
ok after some changes the code is that :


<%

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
%>



it runs almost corect!!!



the only problem is that in the first page is shows 10news
and in the second 3
so if in the first shows 7 the second is corect!


Any ideas??????//

 
My fault, just do this:

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


'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 or nCount = nPageSize
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
nCount = nCount + 1
Loop
Else
response.write(&quot;No Records&quot;)
End if

' Close & clean up
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>
- FateFirst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top