Data from array to mysql query
#1

Hello, i am having trouble getting data from an array into a query. When i dont use the format it perfectly outputs everything i need. But when i format that into a string it starts running every load id through there. Here is the code:
pawn Код:
CMD:importloads(playerid, params[])
{
    new string[512];
    for(new i; i < 1000; i++)
    {  
    // LoadName, MafiaLoad, PayPerUnit, VehicleNeeded, From-Locations, To-Locations
        printf("%s", ALoads[i][LoadName]);
        printf("%f", ALoads[i][PayPerUnit]);
        printf("%i", ALoads[i][PCV_Required]);
        for(new a; a < 10; a++)
        {
            if(ALoads[i][FromLocations][a] != 0)
            {
                printf("From: %i", ALoads[i][FromLocations][a]);
                format(string, sizeof(string), "%s, %i", string, ALoads[i][FromLocations][a]);
            }
            if(ALoads[i][ToLocations][a] != 0)
            {
               printf("To: %i", ALoads[i][ToLocations][a]);
            }
        }
        print(string);
    }
   
    return 1;
}
And this is the log:
Код:
[16:21:24] Wounded person
[16:21:24] 1.000000
[16:21:24] 9
[16:21:24] From: 1
[16:21:24] To: 147
[16:21:24] From: 2
[16:21:24] To: 148
[16:21:24] From: 3
[16:21:24] To: 149
[16:21:24] From: 4
[16:21:24] To: 150
[16:21:24] From: 5
[16:21:24] From: 6
[16:21:24] From: 7
[16:21:24] From: 8
[16:21:24] From: 9
[16:21:24] From: 10
[16:21:24] , 11, 12, 11, 12, 12, 13, 10, 6, 15, 16, 17, 19, 21, 22, 21, 22, 8, 25, 26, 8, 25, 26, 153, 8, 25, 26, 8, 25, 26, 37, 38, 37, 153, 37, 8, 25, 37, 38, 143, 21, 22, 41, 37, 41, 136, 144, 15, 15, 37, 47, 63, 6, 7, 44, 47, 48, 15, 54, 55, 56, 24, 55, 7, 24, 48, 47, 48, 10, 4, 154, 21, 22, 157, 43, 14, 63, 6, 43, 12, 7, 44, 47, 48, 15, 54, 55, 56, 24, 55, 7, 24, 48, 47, 48, 10, 4, 21, 22, 43, 14, 121, 122, 125, 126, 130, 131, 134, 123, 124, 127, 128, 129, 132, 133, 135, 121, 122, 125, 126, 130, 131, 134, 7, 44,
But i just want it to put the from locations in, not all the from locations. just the ones for that load.
Anyone knows?
Reply
#2

I want it to create a string like this:
Код:
From: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Reply
#3

You are placing it throught a loop, how is it not supposed to load every id?
Reply
#4

Well when i print them one by one it works just fine but when i place them into a string it outputs this:
Код:
11, 12, 11, 12, 12, 13, 10, 6, 15, 16, 17, 19, 21, 22, 21, 22, 8, 25, 26, 8, 25, 26, 153, 8, 25, 26, 8, 25, 26, 37, 38, 37, 153, 37, 8, 25, 37, 38, 143, 21, 22, 41, 37, 41, 136, 144, 15, 15, 37, 47, 63, 6, 7, 44, 47, 48, 15, 54, 55, 56, 24, 55, 7, 24, 48, 47, 48, 10, 4, 154, 21, 22, 157, 43, 14, 63, 6, 43, 12, 7, 44, 47, 48, 15, 54, 55, 56, 24, 55, 7, 24, 48, 47, 48, 10, 4, 21, 22, 43, 14, 121, 122, 125, 126, 130, 131, 134, 123, 124, 127, 128, 129, 132, 133, 135, 121, 122, 125, 126, 130, 131, 134, 7, 44,
How am i supposed to do it then?
Reply
#5

You need to clear the string whenever the outermost for-loop runs.
pawn Код:
CMD:importloads(playerid, params[])
{
    new string[512];
    for(new i; i < 1000; i++)
    {  
        string[0] = 0; // Clear the string (just clear the first character)
    // LoadName, MafiaLoad, PayPerUnit, VehicleNeeded, From-Locations, To-Locations
        printf("%s", ALoads[i][LoadName]);
        printf("%f", ALoads[i][PayPerUnit]);
        printf("%i", ALoads[i][PCV_Required]);
        for(new a; a < 10; a++)
        {
            if(ALoads[i][FromLocations][a] != 0)
            {
                printf("From: %i", ALoads[i][FromLocations][a]);
                format(string, sizeof(string), "%s, %i", string, ALoads[i][FromLocations][a]);
            }
            if(ALoads[i][ToLocations][a] != 0)
            {
               printf("To: %i", ALoads[i][ToLocations][a]);
            }
        }
        print(string);
    }
   
    return 1;
}
Reply
#6

Thanks PowerPC it worked!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)