Need help with mysql update...
#1

So basically with mysql I'm on we. It ain't my scripting language.. But still want to learn it.. maybe some one could
explain how to upgrade this code... I'm using MySQL plugin R34...

Here is my code:

pawn Код:
forward LoadGarages();
public LoadGarages()
{
    new arrCoords[15][64];
    new sql[80], row[512];
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM Garages");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    mysql_free_result();
    for (new idx=0; idx<MAX_GARAGES; idx++) {
        format(sql, sizeof(sql), "SELECT * FROM Garages WHERE GarageID=%d", idx);
        mysql_query(sql);
        mysql_store_result();
        if (mysql_num_rows() > 0) {
            mysql_fetch_row(row);
            split(row, arrCoords, '|');
            mysql_free_result();
            Garages[idx][EnterX] = floatstr(arrCoords[1]);
            Garages[idx][EnterY] = floatstr(arrCoords[2]);
            Garages[idx][EnterZ] = floatstr(arrCoords[3]);
            Garages[idx][ExitX] = floatstr(arrCoords[4]);
            Garages[idx][ExitY] = floatstr(arrCoords[5]);
            Garages[idx][ExitZ] = floatstr(arrCoords[6]);
            Garages[idx][EnterAngle] = floatstr(arrCoords[7]);
            Garages[idx][ExitAngle] = floatstr(arrCoords[8]);
            Garages[idx][Owned] = strval(arrCoords[9]);
            strmid(Garages[idx][Owner], arrCoords[10], 0, strlen(arrCoords[10]), 255);
            Garages[idx][Price] = strval(arrCoords[11]);
            Garages[idx][ExitInterior] = strval(arrCoords[12]);
            Garages[idx][Dynamic] = strval(arrCoords[13]);
            Garages[idx][Locked] = strval(arrCoords[14]);

            new string[128];
            if(Garages[idx][Owned] == 0)
            {
                new garagelocation[MAX_ZONE_NAME];
                GetCoords2DZone(Garages[idx][EnterX],Garages[idx][EnterY], garagelocation, MAX_ZONE_NAME);
                format(string, sizeof(string), "[Garage For Sale]\nAddress: %d %s\nPrice: $%d",idx,garagelocation,Garages[idx][Price]);
                garagetext[idx] = Create3DTextLabel(string,0xbec339ff,Garages[idx][EnterX],Garages[idx][EnterY],Garages[idx][EnterZ],5.0,0, 0);
            } else {
                new garagelocation[MAX_ZONE_NAME];
                GetCoords2DZone(Garages[idx][EnterX],Garages[idx][EnterY], garagelocation, MAX_ZONE_NAME);
                format(string, sizeof(string), "[Garage]\nAddress: %d %s\nOwner: %s",idx,garagelocation,Garages[idx][Owner]);
                garagetext[idx] = Create3DTextLabel(string,0xbec339ff,Garages[idx][EnterX],Garages[idx][EnterY],Garages[idx][EnterZ],5.0,0, 0);
            }
        }
    }
    mysql_free_result();
    printf("%d Garages loaded from database", MAX_GARAGES);
    return true;
}

forward SaveGarages(busid);
public SaveGarages(busid)
{
    new query[1024];
    format(query, sizeof(query), "UPDATE Garages SET EnterX=%f,EnterY=%f,EnterZ=%f,ExitX=%f,ExitY=%f,ExitZ=%f,EnterAngle=%f,ExitAngle=%f WHERE GarageID=%d",
    Garages[busid][EnterX],
    Garages[busid][EnterY],
    Garages[busid][EnterZ],
    Garages[busid][ExitX],
    Garages[busid][ExitY],
    Garages[busid][ExitZ],
    Garages[busid][EnterAngle],
    Garages[busid][ExitAngle],
    busid);
    mysql_query(query);
    //printf("Query : %s",query);

    format(query, sizeof(query), "UPDATE Garages SET Owned=%d,Owner='%s',Price=%d,Interior=%d,Dynamic=%d,Open=%d WHERE GarageID=%d",
    Garages[busid][Owned],
    Garages[busid][Owner],
    Garages[busid][Price],
    Garages[busid][ExitInterior],
    Garages[busid][Dynamic],
    Garages[busid][Locked],
    busid);
    mysql_query(query);
    //printf("Query : %s",query);
}
With best regards Scrillex.. And btw big thanks for your help any answers will be appreciated.
Reply


Messages In This Thread
Need help with mysql update... - by Scrillex - 24.01.2014, 23:36
Re: Need help with mysql update... - by Shetch - 24.01.2014, 23:40
Re: Need help with mysql update... - by Scrillex - 24.01.2014, 23:56
Re: Need help with mysql update... - by Scrillex - 25.01.2014, 12:35
Re: Need help with mysql update... - by maddinat0r - 25.01.2014, 12:57
Re: Need help with mysql update... - by Scrillex - 25.01.2014, 13:07
Re: Need help with mysql update... - by maddinat0r - 25.01.2014, 13:11

Forum Jump:


Users browsing this thread: 1 Guest(s)