帮助从MySQL查询获取或显示ColdFusion中的随机记录

帮助从MySQL查询获取或显示ColdFusion中的随机记录

本文介绍了帮助从MySQL查询获取或显示ColdFusion中的随机记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery滚子/滚动器,显示从我的有用的提示数据库表查询返回的记录片段。我想保持滚动约15记录,但不总是前15个记录。

I've got a jquery roller/scroller that displays snippets of records returned from my 'Helpful Hints' database table query. I want to keep the scroller to about 15 records but not always the first 15 records.

编写一个查询更有效率:

Is it more efficient to write a query like:

SELECT *
FROM table
ORDER BY RAND()
LIMIT n

其中返回一个随机结果或返回整个查询,并让我的ColdFusion组件提供一个随机数的查询结果?

Which returns a random result or do I return the whole query and have my ColdFusion component serve up a random number of the query result?

我的滚动器的未来将包括

The future of my scroller will include random records from my 'Items for Sale' table as well, so I need to keep that in mind.

推荐答案

我同意bemace返回一个不会用于Coldfusion的大型结果集是浪费了无法补偿的资源。

I agree with bemace that returning a large result set of values that won't be used to Coldfusion is a waste of resources that can never be recouped.

但是要小心使用(),您应该。

But be careful about using MySQL's RAND() function for ordering - once you're over 100,000 records, it doesn't scale well (see graph), and you should look at using alternatives.

这篇关于帮助从MySQL查询获取或显示ColdFusion中的随机记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 00:12