mysql_query("SELECT * FROM `table_name` WHERE `contest_id` = '2' ORDER BY right_answers desc,time_spent")
I guess your
time_spent column has a
VARCHAR(x) datatype, not a numeric datatype. So, MySQL is ordering the values in alphabetical order like this.
1 10 259 46 5 6 7894 9
Your best repair of this problem is to change the datatype of that column to
INT. (Also repair the right_answers column.)
ALTER TABLE table_name CHANGE COLUMN time_spent time_spent INT NOT NULL DEFAULT '0' ALTER TABLE table_name CHANGE COLUMN right_answers right_answers INT NOT NULL DEFAULT '0'
ORDER BY operation will work numerically and give you expected results.
Your second best repair is to coerce the data to numeric in your
ORDER BY clause, like this:
ORDER BY 0+right_answers DESC, 0+time_spent ASC