php - 随机排序会产生错误

标签 php mysql sql random

这是我想要使用的并且我正在使用的:

$sql="SELECT * from channel ORDER BY rand() LIMIT 6 ";

$rs = $conn->
Execute($sql);

$channellist = $rs->
getrows();

但这会产生错误,整个网站一片空白。
在服务器错误日志中,这是错误:

[28-Jul-2013 09:53:37 America/Detroit] PHP Fatal error:  Call to a member function getrows() on a non-object in /home/hotspitt/public_html/cache/templates_c/%%C3^C37^C3724EE2%%head1.tpl.php on line 60

删除第 60 行( $channellist = $rs->getrows(); )即可使其正常工作。 并将其更改为:

$sql="SELECT * from channel ORDER BY ID desc LIMIT 6 ";

$rs = $conn->
Execute($sql);

$channellist = $rs->
getrows();

让它工作。所以我认为 rand 函数有问题。我不明白为什么 rand() 函数不起作用。
请帮我解决这个问题。

最佳答案

select * from user_details order by rand() limit 10

正在工作,现在询问您的表名 或者你用于执行sql的库

关于php - 随机排序会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052086/

相关文章:

php - 正则表达式删除带数字的单词

php - 准备好的语句是否使用 PHP 跨多个页面加载在服务器端缓存?

c# - 从一个 UI(在网络上)更新数据后如何在其他 UI 上重新加载数据并保持关系?

php - 将 2 个查询合并为 1 个

php - 显示两个 SQL 表中的数据语法解释

sql - 在字符串中查找文本的行和位置

OOP 中的 php uasort

php - 数组推送作为第一个索引 PHP

php - 使用注释的安全方法

sql - Redshift : Getting rank of a row, 按条件过滤