Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Next N' records 1

Status
Not open for further replies.

AlwaysWilling

Programmer
Dec 29, 2005
51
US
Hi, I see this on many sites, and want to know how I do that. I know I can do a 'Next N' records (easycfm has a great tut on that), but what if I wanted to do something like:

1. Show the user a dropdown with 4 choices (10, 25, 50, 100)
2. Then when the user makes their choice that many records come on the screen.

How can I do this?

Thanks!
 
imstillatwork, thanks for getting back to me. I was refrencing the tut at
I like what you did also, but I want to know if its doable to show the user a dropdown of 3-4 choices and let them choose how many recs to be shown.

Like:
<select name="test">
<option value="10" selected>10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="75">75</option>
</select>

So I chose option value 50, then 50 recs should appear.

Thanks!
 
ok, first of, grabs every record from the database no matter what page you are on, but just shows a different section of the query depending on the 'page' you are on. how many rows do you plan on paging through? any more then a hundred or soo, and your going to have performance issues. mine gets only the records needed for the current view, works as fast on 20,000 rows as it does on 20.

ANYWAYS.....

for the one your using..

There is a variable called disp. is is set by cfparam to default to 5. You may have already changed that.

make a form

Remove line:
Code:
<!--- Number of records to display on a page --->
<CFPARAM name="disp" default="5">
in the tutorial code and add this in its place

Code:
<!--- set default number --->
<cfparam name="form.pages" default="5">

<--- set disp variable to always equal form.pages value --->
<cfset disp = form.pages>

then put the form in the page wherever you want
Code:
<form action="" method="post">
<select name="pages">
 <option value="10">10</option>
 <option value="15">15</option>
 <option value="20">20</option>
</select>
<input type="submit" value="set" />
</form>

The form action page is itself, so it just updates the number of rows to display.





Kevin
 
Kevin,

I took a look at your tutorial page and found that utilizing the MySQL LIMIT and OFFSET function is a great strategy.
Now I wonder if we have the similar function in other database (like MS Access or FoxPro tables).

Any comments?
Regards,
mansii
 
imstillatwork said:
mine gets only the records needed for the current view, works as fast on 20,000 rows as it does on 20
that's probably an enthusiastic overstatement :)


your query uses ORDER BY, and i'll bet that it's a lot faster to sort 20 names than it is to sort 20000 names

plus, it does make a database connection and calls the database every time, right? i mean, it has to, because it's returning different rows

and of course calling the database is a lot slower than not calling the database at all

want another strategy?

run the query to return the entire table (just like all those "bad" paging tutorials), but use query caching

that way the user can page forward and back and all over the recordset, and the database will never be called more than once until the query cache expires

in fact, if you do it right, all your visitors can use the same cached query, no matter which different sets of pages they're looking at

sweet, eh?


r937.com | rudy.ca
 
that's an interesting question, and i wonder if you really meant to open that can of worms

:)

most forum searches show results in reverse order of date, so whenever new posts are made, they will be displayed at the top of page 1

if i'm a forum user, and i just scrolled through page 1, and i click Next to go to page 2, i do not want to see a whole bunch of threads that i already saw on page 1 which have been bumped down (onto page 2) by later entries

since you re-query the database, kevin, isn't that what you're doing?

r937.com | rudy.ca
 
So, do you refresh the query only on page 1?
Now your really trying to play with my head!

I have seen forums that do what you described, and it is annoying.

When I first started using the method I described, It was for a helpdesk ticket system that would get a few new tickets per hour, maybe every 10-20 minutes or so.

Kevin
 
am i correct that your method will use

SELECT ... FROM ... ORDER BY postdate desc LIMIT 15,15

to get "page 2" results (when rows per page is 15)

because that SELECT extracts all rows, sorts(*) them all, then delivers you the second set of 15 rows

on a busy system this gives the annoying behaviour, i believe

r937.com | rudy.ca
 
Yes. That is correct.

So on data that changes rarely (but there is a lot of it), a shared cache would work the best, right? Everyone gets the same cached version.

But on a forum, each user needs their own cache to get a correct listing as the page through, until they come to page one again, it should be fresh, showing new entries. would this be correct?



Kevin
 
yes, so on a frequently updated site, cache each user's query results separately

on a stable site (which could be quite busy), cache one query result for everybody

the difference is governed by whether you incorporate the userid into the cached query

at least, that's the way i'd try it :)


r937.com | rudy.ca
 
Sorry for the delay in responding back. I got busy with other things and didn't get the channce to come here.

Thanks all for all the help!

By the way, imstillatwork, I love your site. Very helpful. I love how you have a 'demo' of your code and the code itself. Great for begininers and intermediate programmers!

 
yes, he's got a head start on writing a coldfusion book there :)

may i ask how you are generating the colour-coded html for showing code examples?

r937.com | rudy.ca
 
i do all my html by hand too, which is why i was interested in anything that generates nice colour-coded html for code segments automatically (i.e. by recognizing the code syntax, the way you can in an editor like ultraedit)



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top