Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Pagination Script Help?

    I'm trying to setup paging with numbers in the middle of Previous and Next buttons. I found a script I like but i have one issue with it. Please help many thanks in advance.

    Here the script I found. It uses iNumPerPage for how many records your showing on each page. So if I put 10 per page then it shows ten numbers which is what I want. But I want to show 25 per page it show 25 numbers I only want to show ten numbers at a time. Can you please help me to get this scripted working or if you have an already working script can you please send it to me. Many Thanks!!!!!!

    Code:
    Sub PrintRecordsetNav( iNumPerPage, adodbConnection, adodbCommand, sTable, sURL, sQuerystring )
    	
    	Dim iTtlNumItems, iDBLoc, sSqlTemp, iTtlTemp
    	Dim iDBLocTemp, sURLBeg, iA, iB, x, iTemp, rsObj
    
    	iNumPerPage = 25  'row count
    	iNumCount = 10    'how many numbers to display
    	
    	iDBLoc = CInt(Request("iDBLoc"))
    	iTtlNumItems = CInt(Request("iTtlNumItems"))
    	' Get ttl num of items from the database if it's not already in the QueryString
    	if (iTtlNumItems = 0) then
    		Set rsObj = Server.CreateObject("ADODB.Recordset")
    		sSqlTemp = "SELECT COUNT(*) FROM " & sTable
    		adodbCommand.CommandText = sSqlTemp
    		rsObj.Open adodbCommand
    		If Not(rsObj.EOF) Then
    			iTtlNumItems = rsObj(0)
    		End If
    		rsObj.Close
    		Set rsObj = Nothing
    	end if
    	iTtlTemp = iTtlNumItems \ iNumPerPage	' this is the number of numbers overall (use the "\" to return int)
    	iDBLocTemp = iDBLoc \ iNumPerPage		' this is which number we are currently on (use the "\" to return int)
    	If (sQuerystring <> "") Then
    		sURLBeg = "<a href = """ & sURL & "?" & sQuerystring & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
    	Else
    		sURLBeg = "<a href = """ & sURL & "?iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
    	End If
    	
    	'***** BEGIN DISPLAY *****
    	' Print the "Previous"
    	if (iDBLoc <> 0) then
    		Response.Write sURLBeg & (iDBLoc - iNumPerPage) & """>Previous</a>  "
    	end if
    	' Print the <<
    	if (iDBLocTemp >= iNumPerPage) then
    		Response.Write sURLBeg & (( iDBLocTemp \ iNumPerPage ) * iNumPerPage ^ 2) - (iNumPerPage * 9) & """><<</a> "
    	end if
    	
    	' Print the numbers in between. Print them out in sets of 10.
    	iA = ( iDBLocTemp \ iNumPerPage ) * iNumPerPage
    	iB = ( iDBLocTemp \ iNumPerPage ) * iNumPerPage + iNumPerPage
    	for x = iA to iB
    		iTemp = (x * iNumPerPage)
    		if (iTemp < iTtlNumItems) then	' takes care of extra numbers after the overall final number
    			if (iDBLoc = iTemp) then
    				Response.Write " <b>[" & x+1 & "]</b>"
    			else
    				Response.Write " " & sURLBeg & (x * iNumPerPage) & """>" & x+1 & "</a>"
    			end if
    		else
    			exit for
    		end if
    	next
    	
    	' Print the >>
    	if (iTtlTemp > iDBLocTemp) then
    		if ((iDBLocTemp + iNumPerPage) <= iTtlTemp) then
    			Response.Write " " & sURLBeg & (( iDBLocTemp \ iNumPerPage ) * iNumPerPage + iNumPerPage ) * iNumPerPage & """>>></a> "
    		end if
    	end if
    	' Print the "Next"
    	if ((iDBLoc + iNumPerPage) < iTtlNumItems) then
    		Response.Write "  " & sURLBeg & (iDBLoc + iNumPerPage) & """>Next</a>"
    	end if
    	'***** END DISPLAY *****
    	
    End Sub

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    That's a crappy way to do it, in any case.

    If your SQL that displays the records has any kind of WHERE conditions on it, you would need to duplicate the same WHERE condtions here. On top of that, it means making a separate call to the DB just to get the count.

    If you are using ADODB.Recordset paging in your main code, you should use the same Recordset to get the number of pages, etc.

    So show your mainline code and let's slip in the page numbering stuff.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's my main code. I'm sure there a better way to do this. Any help would be appreciated.

    Code:
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    	<tr>
    		<td valign="top" width="100%">
    		<p style="margin-top: 0; margin-bottom: 0">
    		<table BORDER="0" cellpadding="0" style="border-collapse: collapse" width="100%">
    		<tr>
    		<td align="center">
    <%
    
    countx = 0
    NumPerPage = 24
    
    xmin = Request.QueryString("xmin")
    
    if not (Request.QueryString("Cat") = "") then
    
    Cat = Request.Querystring("Cat")
    
    set rs = Server.Createobject("ADODB.Connection")
    strSQL = "SELECT * FROM PhotoAlbum WHERE PAActive = 'True' AND PACat = " & Cat
    Set rs = ps_database.Execute(strSQL)
    
    else
    
    set rs = Server.Createobject("ADODB.Connection")
    strSQL = "SELECT * FROM PhotoAlbum WHERE PAActive = 'True'"
    Set rs = ps_database.Execute(strSQL)
    
    end if
    
    If rs.EOF Then
        
        Response.Write "<p style=""margin-top: 0; margin-bottom: 0"">&nbsp;</p>"
        Response.Write "<p style=""margin-top: 0; margin-bottom: 0""><font face=""Arial"" size=""2"" color=""#000080""><b>&nbsp;&nbsp;&nbsp;Sorry, No Pictures Found. Please Try Again.</b></font></p>"
       
    Else
       
    Do While NOT rs.Eof
    countx  = countx + 1
    rs.MoveNext
    Loop
    if not len(xmin)> 0 or cint(xmin) < 1 then
    xmin = 1
    xmax = xmin + NumPerPage
    else
    xmin = xmin
    xmax = xmin + NumPerPage
    end if
    Set rs = ps_database.Execute(strSQL)
    %>
    <table BORDER="0" cellpadding="0" style="border-collapse: collapse" width="175">
    <%
    Do While Not rs.EOF
    %>
    <%
    numlines = numlines + 1
    If CInt(numlines) >= CInt(xmin) And CInt(numlines) <= CInt(xmax) - 1 Then
    %>
    <%
    			count = count + 1
    			If count = 1 Then
    			%>
    			<tr>
    			<%
    			End If
    			%>  	
    
    <td width="175">
    <table width="175">
    <tr>
    <td width="175" align="center">
    <a rel="example_group" href="http://t.harmony-christian.org/app_images/gallery_images/<%=rs("PAImage")%>" title="<b><%=rs("PATitle")%></b><br><%=rs("PADesc")%><br>"><img alt="" src="http://t.harmony-christian.org/app_images/gallery_images/<%=rs("PAThumbImage")%>" width="160" /></a>
    		<p style="margin-top: 0; margin-bottom: 0"><font face=arial size=1>&nbsp;</font></p>
    		</td>
    		</tr>
    		</table>
    		<%If count = 3 Then
    		count = 0
    		%></tr><%
    		End If
    		%>
    		
    <%End If
    rs.MoveNext
    Loop
    end if
    %>
    </tr>
    </TABLE>
    </td>
    </tr>
    </table>
    </p>
    </td>
    	</tr>
    </table>
    <%
    	xmin = CInt(Request("xmin"))
    	Items = CInt(Request("Items"))
    	' Get ttl num of items from the database if it's not already in the QueryString
    	if (Items = 0) then
    	if not (Request.QueryString("Cat") = "") then
    
    	Cat = Request.Querystring("Cat")
    
    	set rs = Server.Createobject("ADODB.Connection")
    	strSQL = "SELECT COUNT(*) FROM PhotoAlbum WHERE PAActive = 'True' AND PACat = " & Cat
    	Set rs = ps_database.Execute(strSQL)
    	
    	If Not(rs.EOF) Then
    			Items = rs(0)
    	End If
    	ps_database.Close
    	Set ps_database = Nothing
    
    	else
    
    	set rs = Server.Createobject("ADODB.Connection")
    	strSQL = "SELECT COUNT(*) FROM PhotoAlbum WHERE PAActive = 'True'"
    	Set rs = ps_database.Execute(strSQL)
    	
    	If Not(rs.EOF) Then
    			Items = rs(0)
    	End If
    	ps_database.Close
    	Set ps_database = Nothing
    
    	end if
    	end if
    	
    	iTtlTemp = Items \ NumPerPage	' this is the number of numbers overall (use the "\" to return int)
    	xminTemp = xmin \ NumPerPage		' this is which number we are currently on (use the "\" to return int)
    	If (sQuerystring <> "") Then
    		sURLBeg = "<a class=""link"" href = """ & sURL & "?" & sQuerystring & "&Items=" & Items & "&xmin="
    	Else
    		sURLBeg = "<a class=""link"" href = """ & sURL & "?Items=" & Items & "&xmin="
    	End If
    
    	
    	'***** BEGIN DISPLAY *****
    	%>
    	<% if not (Items < NumPerPage) then %>
    	<div class="pagination_resize">
    	<div class="pagination_nav">
    	<div class="pagination_page_count">
    	<%CurrentPage =(xmin \ NumPerPage +1)%>
    	<%TPageCount =(Items \ NumPerPage)%>
    	Page <%=response.write(CurrentPage)%> of <%=response.write(TPageCount)%>
    	</div>
    	<ul>
    	<%
    		' Print the "Previous"
    	if (xmin <> 0) then
    		Response.Write "<li>"
    		Response.Write sURLBeg & (xmin - NumPerPage) & """>Previous</a>  "
    		Response.Write "</li>"
    	end if
    	' Print the numbers in between. Print them out in sets of 10.
    	iA = ( xminTemp \ NumPerPage ) * NumPerPage
    	iB = ( xminTemp \ NumPerPage ) * NumPerPage + NumPerPage
    	for x = iA to iB
    		iTemp = (x * NumPerPage)
    		if (iTemp < Items) then	' takes care of extra numbers after the overall final number
    			if (xmin = iTemp) then
    				Response.Write "<li class=""active"">"
    				Response.Write " " & x+1 & " "
    				Response.Write "</li>"
    			else
    				Response.Write "<li>"
    				Response.Write " " & sURLBeg & (x * NumPerPage) & """>" & x+1 & "</a>"
    				Response.Write "</li>"
    			end if
    		else
    			exit for
    		end if
    	next
    	
    		' Print the "Next"
    	if ((xmin + NumPerPage) < Items) then
    		Response.Write "<li>"
    		Response.Write "  " & sURLBeg & (xmin + NumPerPage) & """>Next</a>"
    		Response.Write "</li>"
    	end if
    	'***** END DISPLAY *****
    	%>
    	</ul>
    	</div>
    	</div>	
    	<% end if %>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    That code has got some really bogus stuff in it!

    You do this:
    Code:
    set rs = Server.Createobject("ADODB.Connection")
    so that rs is now a connection object.
    But then you do this:
    Code:
    Set rs = ps_database.Execute(strSQL)
    so rs is now a *RECORDSET* object. Creating the connection object was a waste of code.

    But there are lots of other things to change, so hang on.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    THis is utterly bogus, too:
    Code:
    <a rel="example_group" 
       href="http://t.harmony-christian.org/app_images/gallery_images/<%=rs("PAImage")%>"
       title="<b><%=rs("PATitle")%></b><br><%=rs("PADesc")%><br>">
          <img alt="" src="http://t.harmony-christian.org/app_images/gallery_images/<%=rs("PAThumbImage")%>" width="160" />
    </a>
    You can't have HTML tags inside the title= attribute.

    On top of that, the title= should be on the <img> tag and not on the <a> tag.

    And you are making a *HUGE* mistake by using the same images for your thumbnails as you use when they are clicked on! That means that, in order to display the web page, your users have to download *THE ENTIRE SET OF LARGE IMAGES*. You really really need to start creating thumbnails that are ONLY the size you need them to be for the web page. There are freebie programs out there that will generate thumbnails for you. Get one and start using it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    Why do you put each image inside of its own <table>???

    But on top of that, you are forgetting to close the <td> that surrounds each table.

    Code:
    <td width="175">
    <table width="175">
    
    <tr>
    <td width="175" align="center">
    <a rel="example_group" href="http://t.harmony-christian.org/app_images/gallery_images/DSC00025-1.jpg" title="<b>test 7</b><br>test 7<br>"><img alt="" src="http://t.harmony-christian.org/app_images/gallery_images/DSC00025-1.jpg" width="160" /></a>
    		<p style="margin-top: 0; margin-bottom: 0"><font face=arial size=1>&nbsp;</font></p>
    		</td>
    		</tr>
    		</table>
    
    <td>....
    See? Where is the </td> to match that first <td> I show?

    And it's not a huge deal, but (a) the <font> tag is obsolete; you should use a <style> on the <td> instead; and (b) why are you using it, anyway, when all you are displaying with it is a space???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    Okay...here goes.

    Naturally, it is completely untested. So you will likely have to fix my typos and make adjustments here and here.
    Code:
    <!-- put these styles (or similar) in the head of your page -->
    <!-- you can of course adjust these to suit -->
    <style type="text/css">
    table#GALLERY {
        width: 528px;
        border: none;
    }
    table#GALLERY td {
        width: 178px;
        padding: 8px;
        padding-bottom: 0px;
        text-align: center;
    }
    table#GALLERY td a {
        text-decoration: none;
        color: black;
    }
    </style>
    
    
    <!-- then this will generate the gallery for you, so put it where appropriate on page -->
    <%
    ' if you change PIXPERROW, you'll need to adjust the style for table width
    CONST PIXPERROW = 3
    CONST ROWSPERPAGE = 8
    ' these are the paths to your images and thumbnails...hoping you will have both!
    ' for now, I guess THUMBS will have to be same as IMAGES
    CONST IMAGES = "/app_images/gallery_images/"
    CONST THUMBS="/app_images/gallery_images/"
    
    ' first, see if we are coming back to ourselves with a page number
    page = Trim(Request("page"))
    If page = "" Then
        ' if not, then we need to create the SQL string:
        Cat = Trim(Request.Querystring("Cat"))
        SQL = "SELECT * FROM PhotoAlbum WHERE PAActive = 'True'"
        If Cat <> "" Then If IsNumeric(Cat) Then strSQL = strSQL & " AND PACat = " & CDBL(Cat)
        ' save the sql query for use on subsequent pages
        Session("SQL") = SQL
    
        ' validate the page:
        If Not IsNumeric(page) Then page = 1
        page = CINT(page)
    Else
        ' if not, then reuse the SQL we created when we first got here:
        SQL = Session("SQL")
        ' and of course we always start on page 1
        page = 1
    End If
    
    Set rs = Server.Createobject("ADODB.Recordset")
    rs.Open strSQL, ps_database, 3 ' 3 means adOpenStatic !!! important
    
    If rs.EOF Then
    %>
       <p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
       <p style="margin-top: 0; margin-bottom: 0">
           <font face="Arial" size="2" color="#000080">
               <b>&nbsp;&nbsp;&nbsp;Sorry, No Pictures Found. Please Try Again.</b>
           </font>
       </p>
    <%
        Response.End
    End If
    
    ' because we opened using adOpenStatic, we can find out how many pages we have:
    rs.PageSize = PIXPERROW * ROWSPERPAGE
    maxpage = rs.PageCount
    If page > maxpage Then page = maxpage
    If page < 1 Then page = 1
    
    rs.AbsolutePage = page ' so move to that page
    
    ' and now we are ready to generate the rows and columns:
    %>
    
    <table id="GALLERY">
    <%
    For row = 1 To ROWPERPAGE
        If rs.EOF Then Exit For
        Response.Write "<tr>" & vbNewLine
        For col = 1 To PIXPERROW
            img = IMAGES & rs("PAImage")
            ttl = rs("PATitle")
            desc = rs("PADesc")
            thmb = THUMBS & rs("PAThumbImage")
    %>
        <td>
            <a href="<%=img%>" target="BIGPIX">
                <img src="<%=thmb%>" title="<%=desc%>" />
                <br/>
                <%=ttl%>
            </a>
        </td>
    <%
            rs.MoveNext
            If rs.EOF Then Exit For
        Next ' next column
        Response.Write "</tr>" & vbNewLine
    Next ' next row
    %>
    <tr>
       <td colspan="3">
       <ul>
    	<li><a class="link" href="?page=<%=page-1%>">Previous</a></li>
    <%
    ' output up to 9 page links...4 on either side of current page if possible
    first = page-4
    If first < 1 Then 
        first = 1
        last = 9
    Else
        last = page + 4
        If last > maxpage Then
            last = maxpage
            first = last - 8
            If first < 1 Then first = 1
        End If
    End If
    For p = first To last
    %>
            <li><a class="link" href="?page=<%=p%>"><%=p%></a></li>
    <%
    Next
    %>
    	<li><a class="link" href="?page=<%page+1%>">Next</a></li>
       </ul>
       </td>
    </tr>
    </table>
    <%
    rs.Close
    ps_database.close
    %>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had two error message. I had to change the strSQL to SQL in the open string and the other was =page error on the next button. But now the only thing I get is pagination and no images. I added my connection string to my database. Why no images? Path is right and database string is correct. Plus next page just show page 2 doesn't go to page 3 etc.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    What does a dump of the HTML show?

    Bring the page up in your browser then click on the VIEW menu then click on the SOURCE (or PAGE SOURCE) menu item.

    Find the <table> in the HTML and copy/paste it here.

    Or, better, put the page up on the web site using a weird URL nobody will stumble across and show me the URL.

    Good debugging so far, by the by.

    *********

    One thing to add: Put one line of DEBUG into the code.

    Code:
    Set rs = Server.Createobject("ADODB.Recordset")
    Response.Write "<hr>DEBUG SQL: " & SQL & "<hr>" & vbNewLine
    rs.Open SQL, ps_database, 3 ' 3 means adOpenStatic !!! important
    I want to do that to make sure that the query on the 2nd page is correct, still.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the source code. I'm testing the website out here at: http://t.harmony-christian.org/gallerytest.asp

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title></title>
    <!-- put these styles (or similar) in the head of your page -->
    <!-- you can of course adjust these to suit -->
    <style type="text/css">
    table#GALLERY {
        width: 528px;
        border: none;
    }
    table#GALLERY td {
        width: 178px;
        padding: 8px;
        padding-bottom: 0px;
        text-align: center;
    }
    table#GALLERY td a {
        text-decoration: none;
        color: black;
    }
    </style>
    </head>
    
    <body>
    <!-- then this will generate the gallery for you, so put it where appropriate on page -->
    <hr>DEBUG SQL: SELECT * FROM PhotoAlbum WHERE PAActive = 'True'<hr>
    
    
    <table id="GALLERY">
    
    <tr>
       <td colspan="3">
       <ul>
    	<li><a class="link" href="?page=0">Previous</a></li>
    
            <li><a class="link" href="?page=1">1</a></li>
    
            <li><a class="link" href="?page=2">2</a></li>
    
            <li><a class="link" href="?page=3">3</a></li>
    
            <li><a class="link" href="?page=4">4</a></li>
    
            <li><a class="link" href="?page=5">5</a></li>
    
            <li><a class="link" href="?page=6">6</a></li>
    
            <li><a class="link" href="?page=7">7</a></li>
    
            <li><a class="link" href="?page=8">8</a></li>
    
            <li><a class="link" href="?page=9">9</a></li>
    
            <li><a class="link" href="?page=10">10</a></li>
    
    	<li><a class="link" href="?page=2">Next</a></li>
       </ul>
       </td>
    </tr>
    </table>
    
    </body>
    
    </html>

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    OH! I entirely misunderstood your prior post!

    You not only aren't getting any images, you aren't even getting the <tr>...</tr> row markers!

    Ugh...

    AHA! I *think* I see it!
    Code:
    For row = 1 To ROWPERPAGE
    That should be
    Code:
    For row = 1 To ROWSPERPAGE
    ("S" after "ROW")!!!

    With the wrong variable in there, it would be doing
    Code:
    FOR row = 1 TO 0
    and so no rows!

    If that's not the problem, or if that's only part of the problem, let's add in some more debug code:
    Code:
    ' because we opened using adOpenStatic, we can find out how many pages we have:
    rs.PageSize = PIXPERROW * ROWSPERPAGE
    maxpage = rs.PageCount
    If page > maxpage Then page = maxpage
    If page < 1 Then page = 1
    
    rs.AbsolutePage = page ' so move to that page
    
    Response.Write "DEBUG: maxpage is " & maxpage & ", page is " & page & "<br/>"
    Response.Write "DEBUG: EOF is " & rs.EOF & ", pagesize is " & rs.PageSize & "<hr/>"
    
    ' and now we are ready to generate the rows and columns:
    %>
    Leave in the DEBUG of the SQL query, for now. So we can see what happens when you get to another page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK that fixed the images. But paging script is not working. Doesn't go to next page. I added debug scripts. What next?

  • #13
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it fixed. I had to add this instead of page = 1

    Code:
    ' validate the page:
        If Not IsNumeric(page) Then page = 1
        page = CINT(page)

  • #14
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now how do I just show for page links when I have four pages instead of 10 page links? Plus how do I highlight the current page I'm on?
    Last edited by keithboesker; 12-09-2011 at 03:06 AM.

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    Well, my code *should* be showing you no more than 4 pages if there are only 4, so if it doesn't work there's a bug. I'll look more at it. Highlighting current page is easy.

    Hmmm...I think I see why it didn't work! Okay...one fix, one improvement.
    Code:
    <tr>
       <td colspan="3">
       <ul>
    	<li><a class="link" href="?page=<%=page-1%>">Previous</a></li>
    <%
    ' output up to 9 page links...4 on either side of current page if possible
    first = page-4
    If first < 1 Then 
        first = 1
        last = 9
        If last > maxpage Then last = maxpage ' OOPS...I left out this line
    Else
        last = page + 4
        If last > maxpage Then
            last = maxpage
            first = last - 8
            If first < 1 Then first = 1
        End If
    End If
    For p = first To last
        If p = page Then ' *** CODE YOU ASKED FOR: highlight current page
    %>
            <li><a class="currentpage" href="#" onclick="return false;"><%=p%></a></li>
    
    <%
        Else
    %>
            <li><a class="link" href="?page=<%=p%>"><%=p%></a></li>
    <%
        End If
    Next
    %>
    	<li><a class="link" href="?page=<%=(page+1)%>">Next</a></li>
       </ul>
       </td>
    </tr>
    You can define the CSS for "currentpage" (or another class of your choice)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •