我有以下功能,我需要更新$如何在site_views DESC之后按特色视频对视频进行排序我尝试了很多次但显示相同的输出或者我得到空输出。谢谢提前。所以我需要在site_views之后只显示精选视频。
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 list_featured_videos($how = 'added', $limit = '15') { // newest, top views, etc etc etc
$query = mysql_query("SELECT *
FROM `pm_videos`
ORDER BY `pm_videos`.`featured` DESC
LIMIT 0 , 30");
$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;
};
并用:
调用它$featured = list_featured_videos('added');
请注意,使用已添加或site_views会产生相同的结果。
答案 0 :(得分:1)
更改:
$query = mysql_query("SELECT * FROM pm_videos ORDER BY $how DESC LIMIT $limit");
到
$query = mysql_query("SELECT * FROM pm_videos ORDER BY site_views DESC LIMIT $limit");
应该根据您的示例代码中可以看到的内容(您的代码当前通过添加的DESC命令)工作.........
这是你试过的组合之一吗?
答案 1 :(得分:0)
如您previous question所示,您需要一个新的独立功能来显示精选视频:
按要求编辑:
function list_featured_videos($sql) { // newest, top views, etc etc etc
$query = mysql_query( $sql );
$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;
};
现在你可以使用
来调用它$featured = list_featured_videos('SELECT * FROM pm_videos WHERE featured=1 ORDER BY site_views DESC LIMIT 10');
例如。
答案 2 :(得分:0)
$featured = list_featured_videos('SELECT * FROM pm_videos WHERE featured="1" ORDER BY site_views DESC LIMIT 10');