1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

displaying set number of results

Discussion in 'Programming' started by J.P, Aug 13, 2005.

  1. #1
    I know there is not many CF people on the forums but I though I would ask anyway :)

    On a web site I have, people basically leave comments about bars in Puerto Del Carmen and give them a rating out of ten.

    One bar is now upto 77 (or so) comments so the page is getting very long.

    Is there a way to display say 20 comments on the first page, then automatically display the next 20 on a second page and so on?

    I could do it other ways like in a while statement but it means creating the pages by hand which is time.

    Any suggestions welcome.

    JP
     
    J.P, Aug 13, 2005 IP
  2. J.P

    J.P Notable Member

    Messages:
    767
    Likes Received:
    42
    Best Answers:
    3
    Trophy Points:
    205
    #2
    no matter I've sorted a solution.. if you are interested then you can use the following code.

    <CFPARAM name="start" default="1">
    <CFPARAM name="disp" default="10"> (Number of records to display)

    <CFQUERY datasource="Datasource" name="Name">
    SELECT *
    FROM Table
    ORDER BY ID
    WHERE ID = #ID#
    </CFQUERY>


    <CFSET end=Start + disp>
    <CFIF start + disp GREATER THAN name.RecordCount>
    <CFSET end=999>
    <CFELSE>
    <CFSET end=disp>
    </CFIF>

    <CFOUTPUT query="name" startrow="#start#" maxrows="#end#">
    #your out put#
    </CFOUTPUT>


    <CFOUTPUT>
    <br>
    <table border="0" cellpadding="10">
    <tr>

    <CFIF start NOT EQUAL 1>
    <CFIF start GTE disp>
    <CFSET prev=disp>
    <CFSET prevrec=start - disp>
    <CFELSE>
    <CFSET prev=start - 1>
    <CFSET prevrec=1>
    </CFIF>
    <td><font face="wingdings">ç</font> <a href="yourpagename.cfm?ID=#ID#&start=#prevrec#">Previous #prev#
    records</a></td>

    </CFIF>
    <CFIF end LT name.RecordCount>
    <CFIF start + disp * 2 GTE name.RecordCount>
    <CFSET next=name.RecordCount - start - disp + 1>
    <CFELSE>
    <CFSET next=disp>
    </CFIF>
    <td><a href="yourpagename.cfm?ID=#ID#&start=#Evaluate("start + disp")#">Next
    #next# records</a> <font face="wingdings">è</font></td> (<- I had already passed a variable so you must remember to add this into this link)
    </cfif>
    </table>
    </CFOUTPUT>
     
    J.P, Aug 13, 2005 IP