-1

how can i use right code for using ORDER BY id DESC and WHERE

$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']."ORDER BY id DESC";
Hamad
  • 4,988
  • 13
  • 35
  • 65
  • Try adding space before `ORDER BY` – rs. Dec 20 '13 at 18:35
  • Welcome to StackOverflow! Without sounding rude, this question could have been avoided with a little patience and research. If you haven't managed to find the problem after hours of debugging, a quick Google search **"mysql where order by"** would have yielded hundreds of examples, tutorials and explanations. – TheCarver Dec 20 '13 at 19:08
  • http://stackoverflow.com/questions/13620961/order-by-id-desc?rq=1 – TheCarver Dec 20 '13 at 19:19

4 Answers4

2

Add a space here as shown.

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

Also, don't pass your parameters like $_GET or $_POST directly into the SQL query as it will definitely lead to SQL Injection Attacks. Filter those parameters or make use of Prepared Statements.

Shankar Narayana Damodaran
  • 66,874
  • 43
  • 94
  • 124
0

add a space before 'ORDER' at least

 $sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
blotto
  • 3,237
  • 1
  • 18
  • 18
0

You need provide space before ORDER BY

$sel = "SELECT * FROM items where portfolio_id=".$_GET['folio_id']." ORDER BY id DESC";
Krish R
  • 22,188
  • 7
  • 49
  • 57
0

Simply Use this :

$sel = "SELECT * FROM items where portfolio_id ='$_GET[folio_id]' ORDER BY id DESC";
Hassan Sardar
  • 4,153
  • 16
  • 53
  • 91