Problems getting comma separated values
#1

I want to store multiple values in one field in the MySQL database.

This is the way I am currently using to store data (convert to string and concatenate a comma)

PHP код:
for(new 010i++) {
        
Player[playerid][playerPmBlocks][i] = 0;
        
valstr(tempPlayer[playerid][playerPmBlocks][i]);
        
strcat(blockstringtempsizeof(blockstring));
        
strcat(blockstring","sizeof(blockstring));
    } 
This is my enum:
PHP код:
enum PlayerInfo {
    
playerPmBlocks[255]
};
new 
Player[MAX_PLAYERS][PlayerInfo]; 
When I get the data, I am using

PHP код:
cache_get_value(0"ppmblocks"tempblocks255); 
Please tell me a way to remove these commas and store back into the array I am using in the enum.

Also, I am highly unsatisfied by this code. If you guys have any better way to do this, please let me know. This is an urgency.
Reply
#2

Quote:
Originally Posted by JaskaranSingh
Посмотреть сообщение
Also, I am highly unsatisfied by this code. If you guys have any better way to do this, please let me know.
Glad you are because storing multiple values into a single column is the wrong way to go. What you need is another table.
Reply
#3

Quote:
Originally Posted by JaskaranSingh
Посмотреть сообщение
I want to store multiple values in one field in the MySQL database.

This is the way I am currently using to store data (convert to string and concatenate a comma)

PHP код:
for(new 010i++) {
        
Player[playerid][playerPmBlocks][i] = 0;
        
valstr(tempPlayer[playerid][playerPmBlocks][i]);
        
strcat(blockstringtempsizeof(blockstring));
        
strcat(blockstring","sizeof(blockstring));
    } 
This is my enum:
PHP код:
enum PlayerInfo {
    
playerPmBlocks[255]
};
new 
Player[MAX_PLAYERS][PlayerInfo]; 
When I get the data, I am using

PHP код:
cache_get_value(0"ppmblocks"tempblocks255); 
Please tell me a way to remove these commas and store back into the array I am using in the enum.

Also, I am highly unsatisfied by this code. If you guys have any better way to do this, please let me know. This is an urgency.
just use loop trough string until it finds the the comma and until that [i mean like string[128] > string[4] = ","]

then get the string[0-3] characters and store them then remove them from string and repeat that again until the string size ends

or you can use strfind > https://sampwiki.blast.hk/wiki/Strfind


Edit : Using mixed script of functions of >>
StrFind
Strmid
Reply
#4

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Glad you are because storing multiple values into a single column is the wrong way to go. What you need is another table.
Quote:
Originally Posted by JaskaranSingh
Посмотреть сообщение
I want to store multiple values in one field in the MySQL database.

This is the way I am currently using to store data (convert to string and concatenate a comma)

PHP код:
for(new 010i++) {
        
Player[playerid][playerPmBlocks][i] = 0;
        
valstr(tempPlayer[playerid][playerPmBlocks][i]);
        
strcat(blockstringtempsizeof(blockstring));
        
strcat(blockstring","sizeof(blockstring));
    } 
This is my enum:
PHP код:
enum PlayerInfo {
    
playerPmBlocks[255]
};
new 
Player[MAX_PLAYERS][PlayerInfo]; 
When I get the data, I am using

PHP код:
cache_get_value(0"ppmblocks"tempblocks255); 
Please tell me a way to remove these commas and store back into the array I am using in the enum.

Also, I am highly unsatisfied by this code. If you guys have any better way to do this, please let me know. This is an urgency.

Here i was free i just made you a simple of method



PHP код:
/* > tempblocks is your string tight ? with 255 Char size*/
new tempblocks[255]; // Defined Like This Means can store 255 chars
new tempchar 0;
new 
tempstring[128];
new 
temparrycount 0;
cache_get_value(0,"ppmblocks",tempblocks,255);
for(new 
i=0;i<sizeof(tempblocks),i++)
{
    
tempchar strfind(tempblocks,",",true); // tempchar now will have position of that , char in string
    
strmid(tempstring,tempblocks,0,(tempchar-1); // now we have first string before , in tempstring
    
playerPmBlocks[playerid][temparrycount] = strval(tempstring); // use strval if its a number which storing in 
    
temparrycount++;
    
//Now we have to Delete the part we extracted 
    
strdel(tempblocks,0,tempchar);  
    if(
strfind(tempblocks,",",true) == -1) { // lets check if all comos removed so get the last string which is left 
        
playerPmBlocks[playerid][temparrycount] = strval(tempblocks);
        break; 
    } 

Reply
#5

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Glad you are because storing multiple values into a single column is the wrong way to go. What you need is another table.
Thank you. This saved my another 10 hours.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)