我认为这个“问题”无法解决。 我的代码中有不短的查询。
根据变量的值,我需要按ASC或DESC对日期进行排序。
我不想复制查询。我认为我可以像往常一样工作,但事实并非如此。 (?)
如何(是否可能)替换查询ASC或DESC以及变量?
query prepare error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? limit ? offset ?' at line 1
simply example:
...
$sort='asc';
...
select pid,title_posts,txt_posts,count_postvs,usname from posts join usopt on uid_posts=uid_usopt
where uid_posts=? and postacc=1 order by pid ? limit ? offset ?
mysqli_stmt_bind_param($rawdata, 'isii', $uid, $sort, $_SESSION['r2sh'], $offset);
...
答案 0 :(得分:0)
您可以使用order by
:
order by (case when ? = 'asc' then pid end) asc,
pid desc