Reading from SQL
#1

Alright so this code works and all, but I want to limit it out

PHP код:
mysql_format(mysqlquerysizeof(query),"SELECT `Name`,`Message`, `Date`,`Time` FROM `chatlog` WHERE `Name`='%e'",somename);
mysql_tquery(mysqlquery"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
Reply
#2

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).
Reply
#3

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(mysqlquerysizeof(query),"SELECT `Name`,`Message`, `Date`,`Time` FROM `chatlog` WHERE `Name`='%e' ORDER BY `Date` DESC LIMIT 50",somename); 
EDIT:
Soo. Vince was faster
Reply
#4

Ahaaaa, thanks guys, I thought about it and yeah, makes a lot of sense! Thanks +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)