Click to See Complete Forum and Search --> : Only show 6 results
jrthor2
10-01-2003, 09:29 AM
I have a script that reads a list of Newsletters, with the latest month showing first and then descending. For example, my menu shows this:
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
I only want the first 6 to show up. I have the following code, but it shows them starting at the bottom, and going up:
rstFiles.Move (rstFiles.RecordCount - (7 - 1)) 'Show last 6
This displays:
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
I want it to display:
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
Ribeyed
10-01-2003, 02:49 PM
hi,
in your sql:
sql = sql & " ORDER BY tbltable.Monthfield DESC "
jrthor2
10-01-2003, 03:04 PM
I'm not getting this info from a database, it is reading the contents of a directory. Here is the entire code
<%'Code for Newsleter Popup
Dim strPath 'Path of directory to show
Dim objFSO 'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder
' A recordset object variable and some selected constants from adovbs.inc.
' I use these for the sorting code.
Dim rstFiles
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
' You could just as easily read this from some sort of input, but I don't
' need you guys and gals roaming around our server so I've hard coded it to
' a directory I set up to illustrate the sample.
' NOTE: As currently implemented, this needs to end with the /
If Request.QueryString("path") <> "" Then
strPath = Request.QueryString("path")
Else
strPath = "/newsletter/pdf/"
End If
' Create our FSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Get a handle on our folder
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
' First I deal with any subdirectories. I just display them and when you
' click you go to them via plain HTTP. You might want to loop them back
' through this file once you've set it up to take a path as input. It seems
' like the logical thing to do to me at least!
For Each objItem In objFolder.SubFolders
' Deal with the stupid VTI's that keep giving our visitors 404's
If InStr(1, objItem, "_vti", 1) = 0 Then
End If
Next 'objItem
' Now that I've done the SubFolders, do the files!
' In order to be able to sort them easily and still close the FSO relatively
' quickly I'm going to make use of an ADO Recordset object with no attached
' datasource. While it does have a slightly greater overhead then an array
' or dictionary object, it gives me named access to the fields and has built
' in sorting functionality.
Set rstFiles = Server.CreateObject("ADODB.Recordset")
rstFiles.Fields.Append "name", adVarChar, 255
rstFiles.Fields.Append "size", adInteger
rstFiles.Fields.Append "date", adDate
rstFiles.Fields.Append "type", adVarChar, 255
rstFiles.Fields.Append "month", adInteger, 255
rstFiles.Fields.Append "year", adVarChar, 255
rstFiles.Open
For Each objItem In objFolder.Files
rstFiles.AddNew
rstFiles.Fields("name").Value = objItem.Name
rstFiles.Fields("size").Value = objItem.Size
rstFiles.Fields("date").Value = objItem.DateCreated
rstFiles.Fields("type").Value = objItem.Type
MonthLength = Len(rstFiles.Fields("name").Value)-9
'response.write(MonthLength) & "<br>"
fileMonth = Left(rstFiles.Fields("name").Value,MonthLength)
fileYear = Mid(rstFiles.Fields("name").Value,MonthLength +2,4)
Select Case fileMonth
Case "January"
MoNum = 1
Case "February"
MoNum = 2
Case "March"
MoNum = 3
Case "April"
MoNum = 4
Case "May"
MoNum = 5
Case "June"
MoNum = 6
Case "July"
MoNum = 7
Case "August"
MoNum = 8
Case "September"
MoNum = 9
Case "October"
MoNum = 10
Case "November"
MoNum = 11
Case "December"
MoNum = 12
End Select
rstFiles.Fields("month").Value = MoNum
rstFiles.Fields("year").Value = fileYear
'Response.write(rstFiles.Fields("month").Value)
Next 'objItem
' All done! Kill off our File System Object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
' Now we can sort our data and display it:
' Sort ascending by year and secondarily descending by month
rstFiles.Sort = "year Desc, month desc"
rstFiles.MoveFirst
'rstFiles.Move (rstFiles.RecordCount - (7 - 1)) 'Show last 6
%>
HM_Array9 = [
[130,150],
<%
Do While Not rstFiles.EOF
newsletter_nme = Left(rstFiles.Fields("name").Value, InStrRev(rstFiles.Fields("name").Value, ".") - 1)
%>
["<img src=/admin/upload/images/dir_pdf.gif width=16 height=16 align=absmiddle> <%=newsletter_nme%>","http://www.zluth.org/reports/track.asp?r=<%=strPath & rstFiles.Fields("name").Value%>",1,0,0]
<%
If not rstFiles.EOF Then
Response.Write(",")
Else
End If
rstFiles.MoveNext
Loop
' Close our ADO Recordset object
rstFiles.Close
Set rstFiles = Nothing
%>
]
Ribeyed
10-01-2003, 03:31 PM
hi,
ok the problem is that in your code you are ordering by descending then missing out the first 6 then displaying the rest instead of displaying the first 6 and forgetting the rest.
the code up to the recordset is fine, the recordset will look something like this:
1.Sep
2.Aug
3.Jul
4.Jun
5.May
6.Apr
7.Mar
8.Feb
You then move the recordset pointer to count of record set minus 7 -1 (-6). This would put the recordset pointer to 2.Aug.
Try this:
rstFiles.MoveFirst
'display first 6
maxnumtodisplay = 6
for i = 1 to maxmumtodisplay
newsletter_nme = Left(rstFiles.Fields("name").Value, InStrRev(rstFiles.Fields("name").Value, ".") - 1)
%>
["<img src=/admin/upload/images/dir_pdf.gif width=16 height=16 align=absmiddle> <%=newsletter_nme%>","http://www.zluth.org/reports/track.asp?r=<%=strPath & rstFiles.Fields("name").Value%>",1,0,0]
<%
If not rstFiles.EOF Then
Response.Write(",")
Else
End If
rstFiles.MoveNext
next
%>
jrthor2
10-01-2003, 03:43 PM
I tried this, but I am not getting in my menu now when I rollover Newsletters:
HM_Array9 = [
[130,150],
<%
rstFiles.MoveFirst
maxnumtodisplay = 6
for i = 1 to maxmumtodisplay
newsletter_nme = Left(rstFiles.Fields("name").Value, InStrRev(rstFiles.Fields("name").Value, ".") - 1)
%>
["<img src=/admin/upload/images/dir_pdf.gif width=16 height=16 align=absmiddle> <%=newsletter_nme%>","http://www.zluth.org/reports/track.asp?r=<%=strPath & rstFiles.Fields("name").Value%>",1,0,0]
<%
If not rstFiles.EOF Then
Response.Write(",")
Else
End If
rstFiles.MoveNext
Next
' Close our ADO Recordset object
rstFiles.Close
Set rstFiles = Nothing
%>
]
jrthor2
10-01-2003, 03:53 PM
Well, I don't know what I did different, but after manually typing in the code, it works.
thanks!!!
Ribeyed
10-01-2003, 03:56 PM
Hi,
i can't test the code for you, my example was to give you an idea of how to sort your problem. You got to try to give more information on what is happing, what error message your getting and what line it is occuring at.
Saying to me "its not working ????:confused:" or "i'm not getting in my menu now " means absolutly nothing, big fat zero to me.
Did you even try play about with it a bit or did you just cut and paste the code, run it see it wasn't working then run back here to post a useless reply?
I am trying to help you but bloddy hell give me something to go on.