Pulling a date from MySQL DB -
Jing_Chan - 06.08.2018
How can I implement this into a string? I want players to be able to see their registration date on /stats.
Re: Pulling a date from MySQL DB -
Jing_Chan - 06.08.2018
Anyone?
Re: Pulling a date from MySQL DB -
NeXTGoD - 06.08.2018
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(string, sizeof(string), "Registration Date: [%02d/%02d/%02d]\n",
gStr2, PlayerInfo[playerid][Year], PlayerInfo[playerid][Month], PlayerInfo[playerid][Day]);
Hope this helped ya
Re: Pulling a date from MySQL DB -
Banditul18 - 06.08.2018
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(string, sizeof(string), "Registration Date: [%02d/%02d/%02d]\n",
gStr2, PlayerInfo[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.
Re: Pulling a date from MySQL DB -
Calisthenics - 07.08.2018
https://dev.mysql.com/doc/refman/5.5...on_date-format
Re: Pulling a date from MySQL DB -
Jing_Chan - 07.08.2018
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.
Re: Pulling a date from MySQL DB -
NaS - 07.08.2018
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).
Re: Pulling a date from MySQL DB -
Calisthenics - 07.08.2018
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".
Re: Pulling a date from MySQL DB -
Jing_Chan - 07.08.2018
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.
Re: Pulling a date from MySQL DB -
NaS - 07.08.2018
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).