Reading from SQL - 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: Reading from SQL (
/showthread.php?tid=599431)
Reading from SQL -
TwinkiDaBoss - 25.01.2016
Alright so this code works and all, but I want to limit it out
PHP код:
mysql_format(mysql, query, sizeof(query),"SELECT `Name`,`Message`, `Date`,`Time` FROM `chatlog` WHERE `Name`='%e'",somename);
mysql_tquery(mysql, query, "OnChatLoad","i",playerid);
Id want to limit it to LAST 50 entries from the player.
I suppose its where LIMIT 50 comes in but I want to get last 50 not random 50
Re: Reading from SQL -
Vince - 25.01.2016
This is where ORDER BY comes in. I suppose you want to order by time and date in DESCending order, but your setup makes it slightly difficult. You can save an entire timestamp in one column (using either a Unix timestamp with an int column, or using a native datetime column).
Re: Reading from SQL -
Kwarde - 25.01.2016
You have to order by ID of the message (I hope you are using IDs.. AUTO_INCREMENT IDs). Then simply order by ID (descending) and limit 50. Soo you'll have to add ORDER BY `ID` DESC LIMIT 50.
Or, off course, order by date. But somehow I've had struggles with that sometime on my webscript. Could've been a mistake of mine tho
PHP код:
mysql_format(mysql, query, sizeof(query),"SELECT `Name`,`Message`, `Date`,`Time` FROM `chatlog` WHERE `Name`='%e' ORDER BY `Date` DESC LIMIT 50",somename);
EDIT:
Soo. Vince was faster
Re: Reading from SQL -
TwinkiDaBoss - 25.01.2016
Ahaaaa, thanks guys, I thought about it and yeah, makes a lot of sense! Thanks +rep