帮助从MySQL查询获取或显示ColdFusion中的随机记录? [英] Help getting, or displaying, random records in ColdFusion from a MySQL query?

查看:233
本文介绍了帮助从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.

但是要小心使用 MySQL的RAND()函数排序 - 一旦你'超过100,000条记录,因此无法良好扩展 see图表),您应该查看使用替代方案

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中的随机记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆