如何使用正确的代码来使用ORDER BY id DESC and WHERE
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']."ORDER BY id DESC";
答案 0 :(得分:2)
如图所示在此处添加空格。
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
----^
另外,不要将$_GET
或$_POST
之类的参数直接传递给SQL查询,因为它肯定会导致SQL注入攻击。过滤这些参数或使用 Prepared Statements
。
答案 1 :(得分:0)
至少在'ORDER'之前添加一个空格
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
答案 2 :(得分:0)
您需要在ORDER BY
$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
答案 3 :(得分:0)
只需使用:
$sel = "SELECT * FROM items where portfolio_id ='$_GET[folio_id]' ORDER BY id DESC";