使用ORDER BY id DESC和where

时间:2013-12-20 18:33:41

标签: php mysql

如何使用正确的代码来使用ORDER BY id DESC and WHERE

$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']."ORDER BY id DESC";

4 个答案:

答案 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";