1

I want to order the "rank" but it doesnt work, I tried many things but i cant find a solution to this.

$query = $handler->query("SELECT * FROM login ORDER BY rank DESC WHERE rank > 4 AND rank < 7 LIMIT 10");
  • How can I get the code above to work properly?

Things I have tried:

  • putting ORDER BY rank DESC at the end, and;
  • removing DESC, but that also did not work.

I have no idea how to fix this since the webpage does not even load upon requesting it.

Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
  • 2
    `select ... where ... order`. if you had error handling on your query call, you'd have been told about the syntax error. – Marc B Oct 05 '15 at 15:00
  • Yes, your next task (both: learning and implementing) really should be error handling. Or else you will waste your time with wild guessing which is almost certain to lead to superstition and voodoo ;-) – VolkerK Oct 05 '15 at 15:03
  • As an aside, you'll also need to prevent [sql injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) in your queries. That doesn't strictly apply to the example in this question, but it's always a concern :) – Brian Oct 05 '15 at 15:16

2 Answers2

4

Order by should be after where clause

$query = $handler->query("SELECT * FROM login WHERE rank > 4 AND rank < 7 ORDER BY rank DESC LIMIT 10");
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
0

Try like this

$query = $handler->query("SELECT * FROM login WHERE rank > 4 AND rank < 7 ORDER BY rank DESC LIMIT 10")
Arun Krish
  • 2,153
  • 1
  • 10
  • 15