...

View Full Version : Creating a Latest 5 Entries section?



startbar
07-14-2004, 07:51 PM
hi if you use a database for an faq section like this:

<%if pageView="" THEN

dim ordervariable, sortorder
ordervariable = "DateAdded" 'default column to sort on
sortorder = "ASC" 'default sortorder

if (len(request.querystring("sortby")) >= 1) then
ordervariable = request.querystring("sortby")
end if
if (len(request.querystring("sortorder")) >= 1) then
sortorder = request.querystring("sortorder")
end if

strSQL="SELECT * FROM FAQ WHERE Status=1 ORDER BY " & ordervariable & " " & sortorder

' Open the Database
objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF NOT objRS.EOF THEN
'objRS.Filter=objRS("Status")=1
%>

<table><tr><td>

<%
' Write out the list of articles but it will
' only show the ones that have a status of
' 1 which shows they are online
DO WHILE NOT objRS.EOF%>

<img src="q.gif"> <a href="default.asp?view=Display&ID=<%=objRS("ID")%>" class="faqq"><%=objRS("Question")%></a> by <%=objRS("Admin")%> on <%=objRS("DateAdded")%><BR>

<%=objRS("Short")%> <a href="default.asp?view=Display&ID=<%=objRS("ID")%>" class="more">read more..</a><BR>
<img src="/Images/under2.gif"> <img src="/Images/under2.gif"> <img src="/Images/under2.gif"> <img src="/Images/under2.gif">
<BR><BR>

<%
objRS.MoveNext
Loop
objRS.Close
%>

</td></tr></table>

How do you create another section to only show the latest 5 faq's? (on the same page)

thanks

fractalvibes
07-14-2004, 08:10 PM
DO you have a date column or an autonumber column? Sort by that, DESC, and then depending on he RDBMS you are using, limit to top 5.

fv

angst
07-14-2004, 08:42 PM
with mssql server u can use TOP

like:

strSQL="SELECT TOP 5 * FROM FAQ WHERE Status=1 ORDER BY " & ordervariable & " " & sortorder

startbar
07-14-2004, 08:45 PM
where do you write limit 5

what is the code?

startbar
07-14-2004, 08:46 PM
k got it

startbar
07-17-2004, 04:50 PM
hi if you have a page like this
<%if pageView="" THEN

dim ordervariable, sortorder
ordervariable = "DateAdded" 'default column to sort on
sortorder = "ASC" 'default sortorder

if (len(request.querystring("sortby")) >= 1) then
ordervariable = request.querystring("sortby")
end if
if (len(request.querystring("sortorder")) >= 1) then
sortorder = request.querystring("sortorder")
end if

strSQL="SELECT * FROM FAQ WHERE Status=1 ORDER BY " & ordervariable & " " & sortorder

' Open the Database
objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF NOT objRS.EOF THEN
'objRS.Filter=objRS("Status")=1
%>

<table><tr><td>

<%
' Write out the list of articles but it will
' only show the ones that have a status of
' 1 which shows they are online
DO WHILE NOT objRS.EOF%>

<img src="q.gif"> <a href="default.asp?view=Display&ID=<%=objRS("ID")%>" class="faqq"><%=objRS("Question")%></a> by <%=objRS("Admin")%> on <%=objRS("DateAdded")%><BR>

<%=objRS("Short")%> <a href="default.asp?view=Display&ID=<%=objRS("ID")%>" class="more">read more..</a><BR>
<img src="/Images/under2.gif"> <img src="/Images/under2.gif"> <img src="/Images/under2.gif"> <img src="/Images/under2.gif">
<BR><BR>

<%
objRS.MoveNext
Loop
objRS.Close
%>

</td></tr></table>

that shows some information in a table. How can you show the last 5 entries on the page without repeating all the code above?
Becuase i cant use strSQL="SELECT TOP 5 * FROM FAQ WHERE Status=1 ORDER BY " & ordervariable & " " & sortorder on the code at the top cos that will only show 5 entries in the whole database! i just want the last 5 entries at the bottom of the page or something..

please help, thanks

Roy Sinclair
07-19-2004, 07:53 PM
In the future please place your code into the proper [ code ]...[ /code ] blocks so they've be formatted properly on this board, that faint color you used makes it harder for us older folks who's eyes aren't as good as they once were to follow.

If the sort order is changed do you want to show the last five items in the new sort order or only for the default sort order?

If it's for the new sort order then executing five ojbRS.MovePrevious calls after ojbRS.EOF is reached in the first display will set the recordset up for being displayed a second time. If not you just need to add:



ojbRS.Sort = "DateAdded"
ojbRS.MoveLast


... before the five MovePrevious calls. Be sure to trap errors or watch for ojbRS.BOF in case there are less than five records available to be displayed and also make sure you don't execute the ojbRS.Close call until after the second display of records is done.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum