Wrong Result - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Wrong Result (
/showthread.php?tid=589451)
Wrong Result -
PowerF - 19.09.2015
Код:
SELECT `playerName`,`playerScore` FROM `playerdata` where `playerScore` > 100 order by `playerScore` desc LIMIT 0,10
if i have to use this,it will sort wrong
it not goes the higher to lower
but,result will look like this
we will use example player name for this
Cody 991
Bust 987
Mstr 967
... and etc.
and thats not a highest score on the database,the higher score is 20000
Re: Wrong Result -
xVIP3Rx - 19.09.2015
Something's probably wrong with your database, This query works should work, I don't understand why do you use "LIMIT 0,10" and not just 10 though ?
Re: Wrong Result -
Vince - 19.09.2015
Quote:
Originally Posted by xVIP3Rx
I don't understand why do you use "LIMIT 0,10" and not just 10 though ?
|
That means: start from the 0th row and select the next 10, so shouldn't make a difference.
As for the problem: this is likely caused by the column being declared as a text type rather than an integer type, in which case the column will be sorted alphabetically (z-a and also 9-0) rather than numerically.
Re: Wrong Result -
PowerF - 20.09.2015
Bump..
Re: Wrong Result -
xVIP3Rx - 20.09.2015
Vince already gave a possible issue.
Quote:
Originally Posted by Vince
this is likely caused by the column being declared as a text type rather than an integer type, in which case the column will be sorted alphabetically (z-a and also 9-0) rather than numerically.
|
Are you sure you're using numeric values and not any type of strings for the column "playerScore"'s type ?
Re: Wrong Result -
PowerF - 20.09.2015
Yep.
Re: Wrong Result -
BroZeus - 20.09.2015
Either convert the Column type to an integer type(this option is better in my opinion)
Or
Use this query
PHP код:
SELECT playerName,playerScore FROM playerdata where CONVERT(playerscore, SIGNED INTEGER) > 100 order by ORDER BY CONVERT(playerscore, SIGNED INTEGER) desc LIMIT 10
You can avoid using
`` around column names as long as it is not an MySQL reserved keyword or as long as the column name doesn't have any space in its name.
And also LIMIT 0,10 is same as LIMIT 10 so use LIMIT 10 as it will make query smaller.