PHP编写的语句ORDER BY不起作用

时间:2015-02-21 15:03:16

标签: php prepared-statement

我不确定准备好的陈述是否无法订购数据,或者我对此感到不满,我已经获得了此代码:

$by_arrangement     = $_POST['filter_by_arrangement'];
$by_date            = $_POST['filter_by_date'];

$sql = "SELECT id,title,description,champion
        FROM our_videos
        WHERE datemade BETWEEN NOW() - INTERVAL ? DAY AND NOW()
        ORDER BY ?
        LIMIT 10";

$stmt = mysqli_prepare($db_conx, $sql);
mysqli_stmt_bind_param($stmt, "is", $by_date, $by_arrangement);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $single_id, $single_title, $single_description, $single_champion);
while (mysqli_stmt_fetch($stmt))
{
    //GETTING RESULTS
}
mysqli_stmt_close($stmt);

按日期安排一切都很完美,虽然它不起作用OR by by by by by by by by by by by by :::::::::::

datemade DESC
datemade 
views DESC 
views 
comment_count DESC
comment_count

但由于某种原因它总是按ID排序......可能是什么问题?感谢

1 个答案:

答案 0 :(得分:0)

您按列排序,该列不能是绑定变量。

我会看看能否找到参考资料。

我找到了这个:With mysqli and prepared statements can I PASS IN COLUMN NAMES to 'ORDER BY'

它包含一个有用的例子。