Problems getting comma separated values
#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


Messages In This Thread
Problems getting comma separated values - by JaskaranSingh - 11.11.2018, 17:56
Re: Problems getting comma separated values - by Calisthenics - 11.11.2018, 18:04
Re: Problems getting comma separated values - by khRamin78 - 11.11.2018, 18:16
Re: Problems getting comma separated values - by khRamin78 - 11.11.2018, 18:43
Re: Problems getting comma separated values - by JaskaranSingh - 12.11.2018, 06:25

Forum Jump:


Users browsing this thread: 1 Guest(s)