VeloFX
VeloFX

Reputation: 768

Php mysqli select where & order by

i've got a problem with the "order by" tag at the mysqli_query. Actually it works fine but the order by at the end returns just this error:

There was an error: Unknown column 'id' in 'order clause'

$query2 = "SELECT * FROM items WHERE itemownerid = '".$creatorid."' AND game = 1 AND `game_id` = $gameid order by id desc"; 

Upvotes: 1

Views: 5298

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72289

Actually the error itself says that there is no id column exist in your items table and that's why order by id fails.

So change it to valid column name. One example is below:-

$query2 = "SELECT * FROM items WHERE itemownerid = '".$creatorid."' AND game = 1 AND `game_id` = $gameid ORDER BY <write any existing column name of your items table>  DESC"; 

Note:- please take care of the comment suggested by @tadman. Very useful and necessary

Upvotes: 3

Related Questions