我有以下功能,我需要更新 $ how ,以便按 site_views DESC 对视频进行排序 我尝试了很多次,但显示相同的输出或我得到空输出。谢谢提前。
function list_videos($how = 'added', $limit = '15') { // newest, top views, etc etc etc
$query = mysql_query("SELECT * FROM pm_videos ORDER BY $how DESC LIMIT $limit");
$result = '';
while ($row = mysql_fetch_array($query)) {
$results .= "
<div class=\"item\">
<a href=\"" . makevideolink($row['uniq_id'], $row['artist'], $row['video_title']) . "\"><img src=\"" . show_thumb($row['uniq_id']) . "\" alt=\"" . $row['video_title'] . "\" class=\"imag\" width=\"107\" height=\"72\" /></a>
<a href=\"" . makevideolink($row['uniq_id'], $row['artist'], $row['video_title']) . "\" class=\"song_name\">
<span class=\"artist_name\">" . fewchars($row['artist'] . " - " . $row['video_title'], 30) . "</span>
</a>
<span class=\"item_views\">" . pm_number_format($row['site_views']) . " views</span>
</div>";
}
return $results;
}
此处推荐精选视频,但与其他代码(加载播放器)分开显示
function make_voth() {
global $config;
$video_id = '';
$sql = "SELECT uniq_id
FROM pm_videos
WHERE featured = '1'
ORDER BY rand()
LIMIT 1";
$result = @mysql_query($sql);
if (@mysql_num_rows($result) == 0)
{
$sql = "SELECT uniq_id
FROM pm_videos,
ORDER BY rand()
LIMIT 1";
$result = @mysql_query($sql);
$row = @mysql_fetch_assoc($result);
$video_id = $row['uniq_id'];
mysql_free_result($result);
}
else
{
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$video_id = $row['uniq_id'];
}
return $video_id;
}
function show_more_featured($mvotd = '', $limit = 3) {
// todo
}
function show_voth_title() {
// @deprecated
}
答案 0 :(得分:1)
您目前有一个默认显示按added
排序的15行的函数。您可以通过以下两种方式之一进行更改:
更改功能本身。这将使DEFAULT值为site_views
:
function list_videos($how = 'site_views', $limit = '15') { // newest, top views, etc etc etc
现在,如果您致电list_videos()
,您将获得按网站视图desc。
OR
您可以更改在某个地方调用该函数的方式:
list_videos('site_views', 25);
这将按site_views排序,最多显示25个。
list_videos('video_title', 25);
另一个例子,按名称DESC排序可能并不好,但你明白了......
答案 1 :(得分:0)
$featured = list_featured_videos('SELECT * FROM pm_videos WHERE featured="1" ORDER BY site_views DESC LIMIT 10');