注意:未定义的变量:ordenarpor

时间:2017-06-19 07:46:03

标签: php sql sql-server

尝试使用MSSQL数据库中的会话对结果进行排序时出现此错误。我想我已经定义了变量,但我仍然没有定义变量。这是代码:

SELECT u.*, (
    SELECT b.id
    FROM brand AS b
    ORDER BY ABS(b.score - u.score) ASC, b.score DESC -- selects brands ordered by their difference from user's score
    LIMIT 1 -- get just the first brand (with score closest to user's)
)
FROM user AS u

感谢任何人都可以帮我解决这个问题

2 个答案:

答案 0 :(得分:2)

替换这些代码

            $ordernarpor = 'id';
            if(isset($_GET['orderna']))
            {
                $ordernarpor = $_GET['orderna'];
                $_SESSION['orderna'] = $ordernarpor;
            }
            else if(isset($_SESSION['orderna']))
            {
                $ordernarpor = $_SESSION['orderna'];
            }
            $ordenar = '';
            if ($ordernarpor == 'id')
            {
                $ordenar .= " ORDER BY id";
            }
            elseif ($ordernarpor== 'nome')
            {
                $ordenar .= " ORDER BY nome";
            }
            elseif ($ordernarpor== 'idade')
            {
                $ordenar .= " ORDER BY idade";
            }
            elseif($ordernarpor== 'peso')
            {
                $ordenar .= " ORDER BY peso";
            } 

您使用了ordernarpor和ordenarpor。但是你只定义了ordernarpor。

答案 1 :(得分:1)

您已将变量初始化为$ ordernarpor,但使用与$ ordenarpor相同的变量。这只是一个错误的错误。