By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

How to limit the amount of entries listed?

P: 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

Share this Question
Share on Google+
6 Replies


jhardman
Expert 2.5K+
P: 3,405
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

P: 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
Expert 2.5K+
P: 3,405
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

P: 23
I am using microsoft sql server 2005 on windows 2003 r2.
Mar 3 '11 #5

jhardman
Expert 2.5K+
P: 3,405
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

P: 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.