How to limit the amount of entries listed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user65
    New Member
    • May 2010
    • 23

    How to limit the amount of entries listed?

    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.

    Code:
    <%
    		rsG.open "select OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
    		rsCnt2.Open "select count(*) as cnt from tblOrganizations where isFeatured=1",conn
    		if not rsCnt2.eof then
    		finalCount=finalcount+rsCnt2("cnt")
    		end if
    		rsCnt2.close
    		
    		
    		numberRows=finalCount/4
    		incr=finalcount mod 4
    		numberRows=round(numberRows)+incr
    		
    		if rsG.eof and rsG.bof then
    		else					
    					iCol=0
    					while not rsG.EOF 
    					if iCol=numberRows and finalCount>4 then
    					Response.Write "</table></td><td valign=top><table border=0>"
    					iCol=0
    					end if 
    					Response.Write "<tr><td valign=top align=left><a href=groupProfile.asp?grpid=" & rsG("OrganizationID") & ">" & rsG("OrganizationName") & "</a></td></tr>"
    					iCol=iCol+1
    					rsG.MoveNext
    					wend
    		
    		end if
    		
    		%>
    Thanks in advance
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Depending on which type of db you have, one of these might work:
    Code:
    rsG.open "select top 25 OrganizationId,OrganizationName,..."
    or
    Code:
    rsG.open "set rowcount 25; select OrganizationId,OrganizationName,...
    let me know if this helps.

    Jared
    Last edited by jhardman; Mar 3 '11, 02:43 AM. Reason: Removed some asterisks that were inserted in the code by mistake

    Comment

    • user65
      New Member
      • May 2010
      • 23

      #3
      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

      Code:
      Microsoft VBScript compilation error '800a03ea'
      
      Syntax error
      
      /default-new.asp, line 278
      
      rsG.open*"select*top 25 OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
      --------^
      Code:
      Microsoft VBScript compilation error '800a03ea'
      
      Syntax error
      
      /default-new.asp, line 278
      
      rsG.open*"set rowcount 25; select*OrganizationId,OrganizationName,update_date from tblOrganizations where isFeatured=1 order by update_date",conn
      --------^

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        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.
        Code:
        numberRows=25
        Jared

        Comment

        • user65
          New Member
          • May 2010
          • 23

          #5
          I am using microsoft sql server 2005 on windows 2003 r2.

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            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

            Comment

            • user65
              New Member
              • May 2010
              • 23

              #7
              Worked great!! The asterisks were what was causing my foul up. Many thanks Jared!!

              Comment

              Working...