background:
A few days ago, I started the thread "pageSize without RecordSet - is it possible ??" and claimed I had a working solution.
I thought I did have one but oh, I was wrong
The problem:
I need to compare 2 dates, but it won't work for some reason. I've read that one should convert the dates to strings (example Cstr(myDatehere)) but even that won't work.
I also know that when you're working with Access as your database, you should use '#' before and after the dates but since the Board Im making will be built on a SQL-server in the end I do NOT want to use access specific code.
There must be a general(non database-specific) way to do this, right !?
I've attatched a screenshot of my database so it's easier for you to help, if you decides to do so
Here's my code-snippet:
Code:
IF (Page=false) THEN page=1
Forum = Trim(Request.QueryString("Forum"))
IF (pageSize=false OR pageSize >100) THEN pageSize=5
IF (page >1) THEN
strSQL="SELECT TOP "& pageSize &" (SELECT Forums.Threads FROM Forums WHERE Forums.ID="& Forum &") AS ThreadsCount,"&_
"Threads.ID,Threads.Title,Threads.Author,Threads.LastPostDate,Threads.Status,Threads.DatePosted, Threads.Replies, "&_
"(SELECT Users.UserName FROM Users WHERE Users.ID=Threads.Author) AS ThreadAuthor "&_
"FROM Threads WHERE Threads.Forum="& Forum &" AND Threads.LastPostDate < (SELECT Threads.LastPostDate FROM Threads WHERE Threads.LastPostDate < "& Cstr(""&"(SELECT Threads.LastPostDate FROM Threads WHERE Threads.ID="& int((page*pagesize)-pageSize)-1 &")"&"") &") ORDER BY Threads.LastPostDate DESC"
ELSE
strSQL="SELECT TOP "& pageSize &" (SELECT Forums.Threads FROM Forums WHERE Forums.ID="& Forum &") AS ThreadsCount,"&_
"Threads.ID,Threads.Title,Threads.Author,Threads.LastPostDate,Threads.Status,Threads.DatePosted, Threads.Replies, "&_
"(SELECT Users.UserName FROM Users WHERE Users.ID=Threads.Author) AS ThreadAuthor "&_
"FROM Threads WHERE Threads.Forum="& Forum &" ORDER BY Threads.LastPostDate DESC"
END IF
what Im trying to do here is to fetch posts XX from the database, and then if page is > 1, get the date of the last post on previous page, so the script knows where to start on page 2.
Im I clear enough? if not I can upload my whole database along with the page.
an example of the text above)
* display the first xx posts(page one):
topic 1
topic 2
topic 3
...
topic xx
* display next xx posts(page two):
then the script needs to know where to start, I get this by getting the date of the last post on prev. page: int((page*pagesize)-pageSize)-1.
page = which page you're viewing
pagesize = how many topics/page you want to display.
All help is highly appreciated !
thanks,
David
"There are no must's in life unless you provide for someone else than yourself"
I think I know what's wrong with the code above.
when Im developing my tools/applications, I use MS Access as database and when Im done testing I switch to MS SQL Server.
Access and SQL Server does NOT(for some reason) treat dates the same, when you deal with dates in Access you put the sign '#'
just before and after the date, and MS SQL server treat dates as strings.
example)
Date in Acceess: #2001-06-18# (I think this is correct, I know that one must use '#', but Im not sure how)
Date in SQL Server: "2001-06-18"
I think the difference is quite obvious.
/David
"There are no must's in life unless you provide for someone else than yourself"