这是我想要使用的并且我正在使用的:
$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/