Small help [SQL sorting data. Oldest to newest] -
TwinkiDaBoss - 27.01.2016
Alright so Ive got this small problem of mine, not really a problem just something Id like to change now Id better ask someone thats more experienced with me with this.
The code I have works great, but there is 1 thing Id like to change, thats sorting of it, Id like to display the code in a way from the oldest to newest.
Ie current display. Lets says I send last 50 messages to the player that he typed in, it will first load the newest one, so it will end on top.
Message 50 <- sent first
Message 1 <- Sent last
I want of it to be
Message 50 < Sent last
Message 1 < sent first
code
PHP код:
"SELECT `Message` FROM `ic_chat` WHERE `Name`='%e' ORDER BY `ID` DESC LIMIT 50"
Small description about the code
1. It loads LAST 50 messages player entered & sends them to player requesting the log [Works]
2. Sends message that was oldest and then goes to newest one [Works other way around at the moment]
Re: Small help [SQL sorting data. Oldest to newest] -
SickAttack - 27.01.2016
ORDER BY (`ID` * 1) ASC
Re: Small help [SQL sorting data. Oldest to newest] -
TwinkiDaBoss - 27.01.2016
Quote:
Originally Posted by SickAttack
ORDER BY (`ID` * 1) ASC
|
Hmm Im writting the query wrongly then or something.
PHP код:
"SELECT `Message` FROM `ic_chat` WHERE `Name`='%e' ORDER BY (`ID` * 1) ASC DESC LIMIT 50"
Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESC LIMIT 50' at line 1
|
Re: Small help [SQL sorting data. Oldest to newest] -
SickAttack - 27.01.2016
ORDER BY (`ID` * 1) ASC DESC
Check it again. Eyes Wide Open.
Re: Small help [SQL sorting data. Oldest to newest] -
TwinkiDaBoss - 27.01.2016
Quote:
Originally Posted by SickAttack
ORDER BY (`ID` * 1) ASC DESC
Check it again. Eyes Wide Open.
|
Gotcha... Sometimes I simply go full retard, thanks a lot for the help!
Note: To those that this code helps in the future just change ASC DESC to just ASC.
Re: Small help [SQL sorting data. Oldest to newest] -
Nero_3D - 27.01.2016
What is "ID * 1" supposed to do?, Wouldn't that simply output the first 50 of the list ?
I thought the chatlog has x lines and you want the last 50 ?
Just to illuminate me