468,470 Members | 2,147 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,470 developers. It's quick & easy.

How to limit the amount of entries listed?

23
I have the following code setup on my homepage. I was wondering if it would be possible to limit the output to say: 10, 15, 25 entries. Right now it seems limitless.

Expand|Select|Wrap|Line Numbers
  1. <%
  2.         rsG.open "select OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
  3.         rsCnt2.Open "select count(*) as cnt from tblOrganizations where isFeatured=1",conn
  4.         if not rsCnt2.eof then
  5.         finalCount=finalcount+rsCnt2("cnt")
  6.         end if
  7.         rsCnt2.close
  8.  
  9.  
  10.         numberRows=finalCount/4
  11.         incr=finalcount mod 4
  12.         numberRows=round(numberRows)+incr
  13.  
  14.         if rsG.eof and rsG.bof then
  15.         else                    
  16.                     iCol=0
  17.                     while not rsG.EOF 
  18.                     if iCol=numberRows and finalCount>4 then
  19.                     Response.Write "</table></td><td valign=top><table border=0>"
  20.                     iCol=0
  21.                     end if 
  22.                     Response.Write "<tr><td valign=top align=left><a href=groupProfile.asp?grpid=" & rsG("OrganizationID") & ">" & rsG("OrganizationName") & "</a></td></tr>"
  23.                     iCol=iCol+1
  24.                     rsG.MoveNext
  25.                     wend
  26.  
  27.         end if
  28.  
  29.         %>
Thanks in advance
Mar 1 '11 #1

✓ answered by jhardman

Depending on which type of db you have, one of these might work:
Expand|Select|Wrap|Line Numbers
  1. rsG.open "select top 25 OrganizationId,OrganizationName,..."
or
Expand|Select|Wrap|Line Numbers
  1. rsG.open "set rowcount 25; select OrganizationId,OrganizationName,...
let me know if this helps.

Jared

6 1582
jhardman
3,405 Expert 2GB
Depending on which type of db you have, one of these might work:
Expand|Select|Wrap|Line Numbers
  1. rsG.open "select top 25 OrganizationId,OrganizationName,..."
or
Expand|Select|Wrap|Line Numbers
  1. rsG.open "set rowcount 25; select OrganizationId,OrganizationName,...
let me know if this helps.

Jared
Mar 1 '11 #2
user65
23
Greatly appreciate the reply, Thank you Jared. Unfortunately neither of those worked, here is the error I got when implementing them:

I am using microsoft sql 2005 if that helps

Expand|Select|Wrap|Line Numbers
  1. Microsoft VBScript compilation error '800a03ea'
  2.  
  3. Syntax error
  4.  
  5. /default-new.asp, line 278
  6.  
  7. rsG.open*"select*top 25 OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
  8. --------^
Expand|Select|Wrap|Line Numbers
  1. Microsoft VBScript compilation error '800a03ea'
  2.  
  3. Syntax error
  4.  
  5. /default-new.asp, line 278
  6.  
  7. rsG.open*"set rowcount 25; select*OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
  8. --------^
Mar 1 '11 #3
jhardman
3,405 Expert 2GB
Tell me what db you are using and we can adapt this.

Otherwise we can set the numberRows variable to any arbitrary number you want.
Expand|Select|Wrap|Line Numbers
  1. numberRows=25 
Jared
Mar 1 '11 #4
user65
23
I am using microsoft sql server 2005 on windows 2003 r2.
Mar 3 '11 #5
jhardman
3,405 Expert 2GB
Oh duh, stupid mistake! I don't know where those asterisks came from, I didn't notice them when I posted that reply. When I saw it in your reply I thought it was something the error message had inserted to indicate the location of the error. I'll edit my earlier post to correct that.

Both methods should work for sql server.

Jared
Mar 3 '11 #6
user65
23
Worked great!! The asterisks were what was causing my foul up. Many thanks Jared!!
Mar 3 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by James Butler | last post: by
6 posts views Thread by Hannu | last post: by
6 posts views Thread by Daniel Walzenbach | last post: by
1 post views Thread by new2asp | last post: by
10 posts views Thread by orsula | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.