Pulling a date from MySQL DB
#1



How can I implement this into a string? I want players to be able to see their registration date on /stats.

Reply
#2

Anyone?
Reply
#3

You can have an example..

LoadPlayerDataFromSQL
PHP код:
PlayerInfo[playerid][Year]     =     cache_get_field_content_int(i"Year"gMySQL);
PlayerInfo[playerid][Month] =     cache_get_field_content_int(i"Month"gMySQL);
PlayerInfo[playerid][Day]     =     cache_get_field_content_int(i"Day"gMySQL); 
Shows in /Stats
PHP код:
format(stringsizeof(string), "Registration Date: [%02d/%02d/%02d]\n"
gStr2PlayerInfo[playerid][Year], PlayerInfo[playerid][Month], PlayerInfo[playerid][Day]); 
Hope this helped ya
Reply
#4

Quote:
Originally Posted by NeXTGoD
Посмотреть сообщение
You can have an example..

LoadPlayerDataFromSQL
PHP код:
PlayerInfo[playerid][Year]     =     cache_get_field_content_int(i"Year"gMySQL);
PlayerInfo[playerid][Month] =     cache_get_field_content_int(i"Month"gMySQL);
PlayerInfo[playerid][Day]     =     cache_get_field_content_int(i"Day"gMySQL); 
Shows in /Stats
PHP код:
format(stringsizeof(string), "Registration Date: [%02d/%02d/%02d]\n"
gStr2PlayerInfo[playerid][Year], PlayerInfo[playerid][Month], PlayerInfo[playerid][Day]); 
Hope this helped ya
He have a timestamp not separate things to store the date.

OP: You need to load the date as a string not as int or anything else.
Reply
#5

https://dev.mysql.com/doc/refman/5.5...on_date-format
Reply
#6

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Linking me to this page is practically useless information, I need EXAMPLES of how to adapt this knowledge to PAWN - perhaps some people would make sense of that information but me being new to it all I could do with some pointers.
Reply
#7

You can do

Код:
SELECT CONVERT(varchar, REGDATE, 1) FROM ... WHERE ...
where varchar is the target datatype (string), REGDATE is the date you want to convert (the column from your table) and 1 is the format.

https://www.mssqltips.com/sqlservert...ng-sql-server/

There's a table with all the available format IDs, so if you want (for example) MM/DD/YY you can choose format 10.

The result will be one string (the date) which you can get from the cache like any other string (cache_get_value_string or similar).
Reply
#8

Quote:
Originally Posted by Jing_Chan
Посмотреть сообщение
Linking me to this page is practically useless information, I need EXAMPLES of how to adapt this knowledge to PAWN - perhaps some people would make sense of that information but me being new to it all I could do with some pointers.
No, it is not. You can see list of specifiers and format it the way you like.

pawn Код:
SELECT DATE_FORMAT(REGDATE, '%M %d, %Y %H:%i:%s') AS reg_date FROM ...
and then retrieve string, field name is "reg_date".
Reply
#9

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
No, it is not. You can see list of specifiers and format it the way you like.

pawn Код:
SELECT DATE_FORMAT(REGDATE, '%M %d, %Y %H:%i:%s') AS reg_date FROM ...
and then retrieve string, field name is "reg_date".
Do I run this query within the stats command? Then how do I pull the result into the string? That's what I'm asking. Thanks for any pointers.
Reply
#10

Quote:
Originally Posted by Jing_Chan
Посмотреть сообщение
Do I run this query within the stats command? Then how do I pull the result into the string? That's what I'm asking. Thanks for any pointers.
https://sampforum.blast.hk/showthread.php?tid=627520

Look at this for an example (different purpose but everything you need to know is in there). It uses a threaded query, which means the query will be executed seperately and the result returned when it is done.

You execute the query using mysql_tquery and specify a callback.

When the callback is called, the result will be in the cache and you can use the cache_* functions.

The result will be one row (if you only select one player) and one column, except you also get other data.
Column 0 will be the date in this case.

Код:
new date[20];
cache_get_value_index(0, 0, date, sizeof(date)); // row 0, column 0
So you can add a callback for the stats command and show the stats there, after extracting all the data from the cache.
You can also do this instantly without a threaded query by using mysql_query, which returns a cache ID from which you can get the data exactly like a threaded query (same cache functions).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)