按 DESC 排序不适用于自定义变量 $how [英] Order by DESC not working for custom variable $how

查看:22
本文介绍了按 DESC 排序不适用于自定义变量 $how的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下功能,我需要更新 $how 以便它按 site_views DESC 对视频进行排序我尝试了很多次,但显示相同的输出或我得到空输出.提前致谢.

function list_videos($how = ' added', $limit = '15') {//最新的、顶视图等等等$query = mysql_query("SELECT * FROM pm_videos ORDER BY $how DESC LIMIT $limit");$结果 = '';while ($row = mysql_fetch_array($query)) {$results .= "<div class=\"item\"><a href=\"" .makevideolink($row['uniq_id'], $row['artist'], $row['video_title']) ."\"><span class=\"artist_name\">" . somechars($row['artist'] . " - " . $row['video_title'], 30) . "</span></a><span class=\"item_views\">" .pm_number_format($row['site_views']) ." 视图</span>

";}返回 $results;}

此处精选视频被调用,但与其他代码分开显示(随播放器加载)

function make_voth() {全局 $config;$video_id = '';$sql = "选择 uniq_id来自 pm_videosWHERE 特色 = '1'按 rand() 排序限制 1";$result = @mysql_query($sql);如果 (@mysql_num_rows($result) == 0){$sql = "选择 uniq_id来自 pm_videos,按 rand() 排序限制 1";$result = @mysql_query($sql);$row = @mysql_fetch_assoc($result);$video_id = $row['uniq_id'];mysql_free_result($result);}别的{$row = mysql_fetch_assoc($result);mysql_free_result($result);$video_id = $row['uniq_id'];}返回 $video_id;}功能 show_more_featured($mvotd = '', $limit = 3) {// 去做}函数 show_voth_title() {//@已弃用}

解决方案

您当前有一个默认显示 15 行按 added 排序的功能.您可以通过以下两种方式之一进行更改:

改变函数本身.这将使 DEFAULT 值成为 site_views:

function list_videos($how = 'site_views', $limit = '15') {//最新、顶视图等等等

现在,如果您调用 list_videos(),您将获得 15 个按网站浏览量降序排列的结果.

你可以改变你在某个地方调用函数的方式:

list_videos('site_views', 25);

这将按 site_views 排序,最多显示 25 个.

list_videos('video_title', 25);

另一个例子,按名称 DESC 排序可能不太好,但你明白了......

I have the following functions , I need to update $how so it sort videos by site_views DESC I tried a lot of times but same output is displaying or I get empty output.Thanks in advance.

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;
}

Here featured videos are called but displayed separately from the other code(loaded with the player)

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
}

解决方案

You currently have a function that defaults to showing 15 rows sorted by added. You can change this one of two ways:

Change the function itself. This will make the DEFAULT value be site_views:

function list_videos($how = 'site_views', $limit = '15') { // newest, top views, etc etc etc

Now if you call list_videos(), you will get 15 results ordered by site views desc.

OR

You can just change how you call the function in a certain place:

list_videos('site_views', 25);

This would order by site_views and show up to 25.

list_videos('video_title', 25);

Another example, probably not good to sort by name DESC but you get the idea...

这篇关于按 DESC 排序不适用于自定义变量 $how的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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