Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a Latest 5 Entries section?

    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

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    with mssql server u can use TOP

    like:

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

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    where do you write limit 5

    what is the code?

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    k got it

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying stats like latest links etc..

    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

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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.
    Last edited by Roy Sinclair; 07-19-2004 at 09:11 PM.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •