ASP/SQL How to Query always the 2nd & 3rd records sortedby date

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default ASP/SQL How to Query always the 2nd & 3rd records sortedby date

    Hello I have a news page and it is dynamic: The first headline has an image
    and a short description and is always the latest story because its sorted by
    date. Now underneath that I want to have the titles from the second and third
    story and just the titles no image. How could I create a recordset which will
    always query the table sorted by date, for the 2nd and 3rd most recent story?
    Speegs

    Speegs Guest

  2. Similar Questions and Discussions

    1. date query problem, date in variable
      I am using the following query : $query_archief = "SELECT * FROM vacatures where dd_eind_plaatsing < $dd_eind_plaatsing_archief1" note:...
    2. display records >(higher) than todays date?
      hi, I have a vacancies table which displays vancanies added into a database. I want to display the records that have todays date or higher in the...
    3. Filter records by date and time
      any chance to help me on this pls .. can anyone tell me how i can sort my table by date and time i wanna put down specific DATE and TIME into my db...
    4. How to display records from todays date and specifiec time of the day
      Hi all any idea how to display specific record on current date and time of the day ... i did managed to display it for the date and drop it on...
    5. error when submit new DATE records
      I have to insert new records by a add_form.asp. the database is access. When I submit a record, if the DATE textbox is empty, I have an error...
  3. #2

    Default Re: ASP/SQL How to Query always the 2nd & 3rd records sorted by date

    You only need to use one recordset.
    Grab the data for the latest three news articles.
    Display the first record as you currently do.
    Use a Recordset.MoveNext() statement to move the recordset position to the
    next record after the first item is displayed.
    Display the next one.
    Move next again
    Display last one.

    SQL example:

    SELECT TOP 3 *
    FROM newstable
    WHERE criteria
    ORDER BY dateadded DESC

    HTH
    Rob
    [url]http://robgt.com/[/url]


    RobGT Guest

  4. #3

    Default Re: ASP/SQL How to Query always the 2nd & 3rd recordssorted by date

    How would I then apply the Recordset.MoveNext() to the event name which is the
    same as the news title lets say? here is my pages and I really appreciate this
    help Rob. <%@LANGUAGE='VBSCRIPT' CODEPAGE='1252'%> <!--#include
    file='Connections/connwrs.asp' --> <% Dim Recordset1 Dim Recordset1_numRows
    Set Recordset1 = Server.CreateObject('ADODB.Recordset')
    Recordset1.ActiveConnection = MM_connwrs_STRING Recordset1.Source = 'SELECT *
    FROM YASIEvent ORDER BY datenow DESC' Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2 Recordset1.LockType = 1 Recordset1.Open()
    Recordset1_numRows = 0 %> <% ' *** Recordset Stats, Move To Record, and Go To
    Record: declare stats variables Dim Recordset1_total Dim Recordset1_first Dim
    Recordset1_last ' set the record count Recordset1_total =
    Recordset1.RecordCount ' set the number of rows displayed on this page If
    (Recordset1_numRows < 0) Then Recordset1_numRows = Recordset1_total Elseif
    (Recordset1_numRows = 0) Then Recordset1_numRows = 1 End If ' set the first
    and last displayed record Recordset1_first = 1 Recordset1_last =
    Recordset1_first + Recordset1_numRows - 1 ' if we have the correct record
    count, check the other stats If (Recordset1_total <> -1) Then If
    (Recordset1_first > Recordset1_total) Then Recordset1_first =
    Recordset1_total End If If (Recordset1_last > Recordset1_total) Then
    Recordset1_last = Recordset1_total End If If (Recordset1_numRows >
    Recordset1_total) Then Recordset1_numRows = Recordset1_total End If End
    If %> <% Dim MM_paramName %> <% ' *** Move To Record and Go To Record: declare
    variables Dim MM_rs Dim MM_rsCount Dim MM_size Dim MM_uniqueCol Dim MM_offset
    Dim MM_atTotal Dim MM_paramIsDefined Dim MM_param Dim MM_index Set MM_rs =
    Recordset1 MM_rsCount = Recordset1_total MM_size = Recordset1_numRows
    MM_uniqueCol = '' MM_paramName = '' MM_offset = 0 MM_atTotal = false
    MM_paramIsDefined = false If (MM_paramName <> '') Then MM_paramIsDefined =
    (Request.QueryString(MM_paramName) <> '') End If %> <% ' *** Move To Record:
    handle 'index' or 'offset' parameter if (Not MM_paramIsDefined And MM_rsCount
    <> 0) then ' use index parameter if defined, otherwise use offset parameter
    MM_param = Request.QueryString('index') If (MM_param = '') Then MM_param
    = Request.QueryString('offset') End If If (MM_param <> '') Then
    MM_offset = Int(MM_param) End If ' if we have a record count, check if we
    are past the end of the recordset If (MM_rsCount <> -1) Then If
    (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
    If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat
    region MM_offset = MM_rsCount - (MM_rsCount Mod MM_size) Else
    MM_offset = MM_rsCount - MM_size End If End If End If ' move
    the cursor to the selected record MM_index = 0 While ((Not MM_rs.EOF) And
    (MM_index < MM_offset Or MM_offset = -1)) MM_rs.MoveNext MM_index =
    MM_index + 1 Wend If (MM_rs.EOF) Then MM_offset = MM_index ' set
    MM_offset to the last possible record End If End If %> <% ' *** Move To
    Record: if we dont know the record count, check the display range If
    (MM_rsCount = -1) Then ' walk to the end of the display range for this page
    MM_index = MM_offset While (Not MM_rs.EOF And (MM_size < 0 Or MM_index <
    MM_offset + MM_size)) MM_rs.MoveNext MM_index = MM_index + 1 Wend
    ' if we walked off the end of the recordset, set MM_rsCount and MM_size If
    (MM_rs.EOF) Then MM_rsCount = MM_index If (MM_size < 0 Or MM_size >
    MM_rsCount) Then MM_size = MM_rsCount End If End If ' if we
    walked off the end, set the offset based on page size If (MM_rs.EOF And Not
    MM_paramIsDefined) Then If (MM_offset > MM_rsCount - MM_size Or MM_offset =
    -1) Then If ((MM_rsCount Mod MM_size) > 0) Then MM_offset =
    MM_rsCount - (MM_rsCount Mod MM_size) Else MM_offset = MM_rsCount
    - MM_size End If End If End If ' reset the cursor to the
    beginning If (MM_rs.CursorType > 0) Then MM_rs.MoveFirst Else
    MM_rs.Requery End If ' move the cursor to the selected record MM_index =
    0 While (Not MM_rs.EOF And MM_index < MM_offset) MM_rs.MoveNext
    MM_index = MM_index + 1 Wend End If %> <% ' *** Move To Record: update
    recordset stats ' set the first and last displayed record Recordset1_first =
    MM_offset + 1 Recordset1_last = MM_offset + MM_size If (MM_rsCount <> -1)
    Then If (Recordset1_first > MM_rsCount) Then Recordset1_first =
    MM_rsCount End If If (Recordset1_last > MM_rsCount) Then
    Recordset1_last = MM_rsCount End If End If ' set the boolean used by hide
    region to check if we are on the last record MM_atTotal = (MM_rsCount <> -1 And
    MM_offset + MM_size >= MM_rsCount) %> <% ' *** Go To Record and Move To Record:
    create strings for maintaining URL and Form parameters Dim MM_keepNone Dim
    MM_keepURL Dim MM_keepForm Dim MM_keepBoth Dim MM_removeList Dim MM_item Dim
    MM_nextItem ' create the list of parameters which should not be maintained
    MM_removeList = '&amp;index=' If (MM_paramName <> '') Then MM_removeList =
    MM_removeList &amp; '&amp;' &amp; MM_paramName &amp; '=' End If MM_keepURL=''
    MM_keepForm='' MM_keepBoth='' MM_keepNone='' ' add the URL parameters to the
    MM_keepURL string For Each MM_item In Request.QueryString MM_nextItem =
    '&amp;' &amp; MM_item &amp; '=' If (InStr(1,MM_removeList,MM_nextItem,1) = 0)
    Then MM_keepURL = MM_keepURL &amp; MM_nextItem &amp;
    Server.URLencode(Request.QueryString(MM_item)) End If Next ' add the Form
    variables to the MM_keepForm string For Each MM_item In Request.Form
    MM_nextItem = '&amp;' &amp; MM_item &amp; '=' If
    (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then MM_keepForm = MM_keepForm
    &amp; MM_nextItem &amp; Server.URLencode(Request.Form(MM_item)) End If Next
    ' create the Form + URL string and remove the intial '&amp;' from each of the
    strings MM_keepBoth = MM_keepURL &amp; MM_keepForm If (MM_keepBoth <> '') Then
    MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1) End If If (MM_keepURL
    <> '') Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1) End If If
    (MM_keepForm <> '') Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) -
    1) End If ' a utility function used for adding additional parameters to these
    strings Function MM_joinChar(firstItem) If (firstItem <> '') Then
    MM_joinChar = '&amp;' Else MM_joinChar = '' End If End Function %> <% '
    *** Move To Record: set the strings for the first, last, next, and previous
    links Dim MM_keepMove Dim MM_moveParam Dim MM_moveFirst Dim MM_moveLast Dim
    MM_moveNext Dim MM_movePrev Dim MM_urlStr Dim MM_paramList Dim MM_paramIndex
    Dim MM_nextParam MM_keepMove = MM_keepBoth MM_moveParam = 'index' ' if the
    page has a repeated region, remove 'offset' from the maintained parameters If
    (MM_size > 1) Then MM_moveParam = 'offset' If (MM_keepMove <> '') Then
    MM_paramList = Split(MM_keepMove, '&amp;') MM_keepMove = '' For
    MM_paramIndex = 0 To UBound(MM_paramList) MM_nextParam =
    Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),'=') - 1)
    If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then MM_keepMove =
    MM_keepMove &amp; '&amp;' &amp; MM_paramList(MM_paramIndex) End If
    Next If (MM_keepMove <> '') Then MM_keepMove = Right(MM_keepMove,
    Len(MM_keepMove) - 1) End If End If End If ' set the strings for the
    move to links If (MM_keepMove <> '') Then MM_keepMove =
    Server.HTMLEncode(MM_keepMove) &amp; '&amp;' End If MM_urlStr =
    Request.ServerVariables('URL') &amp; '?' &amp; MM_keepMove &amp; MM_moveParam
    &amp; '=' MM_moveFirst = MM_urlStr &amp; '0' MM_moveLast = MM_urlStr &amp;
    '-1' MM_moveNext = MM_urlStr &amp; CStr(MM_offset + MM_size) If (MM_offset -
    MM_size < 0) Then MM_movePrev = MM_urlStr &amp; '0' Else MM_movePrev =
    MM_urlStr &amp; CStr(MM_offset - MM_size) End If %> <!DOCTYPE HTML PUBLIC
    '-//W3C//DTD HTML 4.01 Transitional//EN'
    'http://www.w3.org/TR/html4/loose.dtd'> <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
    function Thumbnail(tmb_suff,tmb_filename) Dim tmb_NewFilename, tmb_Path,
    tmb_PosPath, tmb_PosExt if not isnull(tmb_filename) then tmb_PosPath =
    InStrRev(tmb_filename,'/') tmb_Path = '' if tmb_PosPath > 0 then
    tmb_Path = mid(tmb_filename,1,tmb_PosPath) end if tmb_PosExt =
    InStrRev(tmb_filename,'.') if tmb_PosExt > 0 then tmb_NewFilename =
    tmb_Path &amp; mid(tmb_filename,tmb_PosPath+1,tmb_PosExt-(tmb_PosPath+1)) &amp;
    tmb_suff &amp; '.jpg' else tmb_NewFilename = tmb_Path &amp;
    mid(tmb_filename,tmb_PosPath+1,len(tmb_filename)-tmb_PosPath) &amp; tmb_suff
    &amp; '.jpg' end if end if Thumbnail = tmb_NewFilename end function
    </SCRIPT> <html> <head> <meta http-equiv='Content-Type' content='text/html;
    charset=iso-8859-1'> <title>news page</title> <link href='wrs_styles.css'
    rel='stylesheet' type='text/css'> </head> <body> <table width='100%' > <tr>
    <td><table width='550'> <tr> <td
    class='titleTan'>&amp;nbsp;</td> </tr> </table> <br> <table
    width='550'> <tr> <td width='275' valign='top'><table
    width='100%' border='0'> <% If Not Recordset1.EOF Or Not
    Recordset1.BOF Then %> <tr valign='top'> <td
    width='16%'><img src='<%=
    Thumbnail('_small',(Recordset1.Fields.Item('image1 ').Value)) %>'
    border='0'></td> <td width='84%' class='copyright'><div
    align='left'><strong><%=(Recordset1.Fields.Item('e ventname').Value)%></strong>

    <%=Left(Recordset1.Fields.Item('eventdescription') ,150)%>.....<a href='#'>read
    more</a> </div></td> </tr> <% End If ' end Not
    Recordset1.EOF Or NOT Recordset1.BOF %> <
    Speegs Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139