Raised This Month: $12 Target: $400
 3% 

Stringify array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Trum
AlliedModders Donor
Join Date: Jan 2017
Old 08-24-2020 , 04:16   Stringify array?
Reply With Quote #1

Hay!

So I would like to send an array to my database table column. How can I stringify the array? I did not find anything on the API nor forums.
Trum is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-24-2020 , 04:32   Re: Stringify array?
Reply With Quote #2

If it's an array of strings: https://sourcemod.dev/#/string/function.ImplodeStrings
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Trum
AlliedModders Donor
Join Date: Jan 2017
Old 08-26-2020 , 04:07   Re: Stringify array?
Reply With Quote #3

So with that I'm able to get an array into this literal string: ["Hello", "there"] which I can then for example print in chat or send directly to my database?

Just like JSON.stringify in JavaScript

Last edited by Trum; 08-26-2020 at 04:08.
Trum is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-26-2020 , 05:31   Re: Stringify array?
Reply With Quote #4

The description is pretty clear.
Quote:
Joins an array of strings into one string, with a "join" string inserted in
between each given string. This function complements ExplodeString.
So given "," as the join string, the result will be "Hello,there". You can then explode the string on "," to get the original array.

You have to pick a join string that doesn't occur in your array values, so you shouldn't use this if your array contains for example player names, as you don't know what characters people might put in their name.


But as mentioned on Discord, you shouldn't put multiple values into one database column!

There is no performance gain to using one column. In fact you're adding unnecessary code by turning the array into a string and then turning it back into an array every time you want to display the values.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Trum
AlliedModders Donor
Join Date: Jan 2017
Old 08-27-2020 , 03:20   Re: Stringify array?
Reply With Quote #5

Alright, thanks for explaining more detailed.

I think I'm going to save the kills data in a new row in another table, is that the best way to go?
Trum is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode