Loading business with MySQL
#1

Hello, I'm trying to save the business from my server for MySQL here I am trying to read because I inserted in the database. Manually.

I guess you're wrong as well, I just want it to carry business, but when I start it from the crash. the sa-mp server closes alone.

My attempts:

pawn Код:
public LoadBizz()
{
        new idx;
        while (idx < sizeof(BizzInfo))
        {
            new Str[237];
            format(Str,115,"SELECT `Vendida`, `Dono`, `Mensagem`, `Extorcao`, `EntradaX`, `EntradaY`, `EntradaZ`, `SaidaX`, `SaidaY`, `SaidaZ`,");
            format(Str,237,"%s `LevelNecessario`, `PrecoCompra`, `EntradaCusto`, `Till`, `Trancada`, `Interior` FROM `empresas` WHERE `ID`='%i'",Str, idx);
            mysql_function_query(Connect, Str, true, "LooadBizz", "i", idx);
            idx++;
        }
        printf("%d Empresas Carregadas", idx);
    return 1;
}
pawn Код:
forward LooadBizz(idx);
public LooadBizz(idx)
{
    new rows, fields,temp[25];
    cache_get_data(rows, fields);
    if(rows)
    {
    cache_get_row(0, 0, temp), BizzInfo[idx][bOwned] = strval(temp);
    cache_get_row(0, 1, temp), BizzInfo[idx][bOwner] = strval(temp);
    cache_get_row(0, 2, temp), BizzInfo[idx][bMessage] = strval(temp);
    cache_get_row(0, 3, temp), BizzInfo[idx][bExtortion] = strval(temp);
    cache_get_row(0, 4, temp), BizzInfo[idx][bEntranceX] = strval(temp);
    cache_get_row(0, 5, temp), BizzInfo[idx][bEntranceY] = strval(temp);
    cache_get_row(0, 6, temp), BizzInfo[idx][bEntranceZ] = strval(temp);
    cache_get_row(0, 7, temp), BizzInfo[idx][bExitX] = strval(temp);
    cache_get_row(0, 8, temp), BizzInfo[idx][bExitY] = strval(temp);
    cache_get_row(0, 9, temp), BizzInfo[idx][bExitZ] = strval(temp);
    cache_get_row(0, 10, temp), BizzInfo[idx][bLevelNeeded] = strval(temp);
    cache_get_row(0, 11, temp), BizzInfo[idx][bBuyPrice] = strval(temp);
    cache_get_row(0, 12, temp), BizzInfo[idx][bEntranceCost] = strval(temp);
    cache_get_row(0, 13, temp), BizzInfo[idx][bTill] = strval(temp);
    cache_get_row(0, 14, temp), BizzInfo[idx][bLocked] = strval(temp);
    cache_get_row(0, 15, temp), BizzInfo[idx][bInterior] = strval(temp);
    }
    return 1;
}

I will be very grateful to those who help me.

Thank you!

and sorry for the English.

@EDIT: In total there are 7 business.
Database:
Reply
#2

I really need help pleease :/
Reply
#3

pawn Код:
mysql_function_query(Connect, "SELECT * FROM `empresas`", true, "LoadBizz", "");

forward LoadBizz();
public LoadBizz()
{
    new rows, fields,temp[26],TotalBusinesses;
    cache_get_data(rows, fields);
    while(TotalBusinesses < rows)
    {
        cache_get_row(TotalBusinesses, 0, temp), BizzInfo[TotalBusinesses][bOwned] = strval(temp);
        cache_get_row(TotalBusinesses, 1, temp), format(BizzInfo[TotalBusinesses][bOwner],26,temp);
        cache_get_row(TotalBusinesses, 2, temp), format(BizzInfo[TotalBusinesses][bMessage],26,temp);
        cache_get_row(TotalBusinesses, 3, temp), BizzInfo[TotalBusinesses][bExtortion] = strval(temp);
        cache_get_row(TotalBusinesses, 4, temp), BizzInfo[TotalBusinesses][bEntranceX] = floatstr(temp);
        cache_get_row(TotalBusinesses, 5, temp), BizzInfo[TotalBusinesses][bEntranceY] = floatstr(temp);
        cache_get_row(TotalBusinesses, 6, temp), BizzInfo[TotalBusinesses][bEntranceZ] = floatstr(temp);
        cache_get_row(TotalBusinesses, 7, temp), BizzInfo[TotalBusinesses][bExitX] = floatstr(temp);
        cache_get_row(TotalBusinesses, 8, temp), BizzInfo[TotalBusinesses][bExitY] = floatstr(temp);
        cache_get_row(TotalBusinesses, 9, temp), BizzInfo[TotalBusinesses][bExitZ] = floatstr(temp);
        cache_get_row(TotalBusinesses, 10, temp), BizzInfo[TotalBusinesses][bLevelNeeded] = strval(temp);
        cache_get_row(TotalBusinesses, 11, temp), BizzInfo[TotalBusinesses][bBuyPrice] = strval(temp);
        cache_get_row(TotalBusinesses, 12, temp), BizzInfo[TotalBusinesses][bEntranceCost] = strval(temp);
        cache_get_row(TotalBusinesses, 13, temp), BizzInfo[TotalBusinesses][bTill] = strval(temp);
        cache_get_row(TotalBusinesses, 14, temp), BizzInfo[TotalBusinesses][bLocked] = strval(temp);
        cache_get_row(TotalBusinesses, 15, temp), BizzInfo[TotalBusinesses][bInterior] = strval(temp);
        TotalBusinesses++;
    }
    printf("%d businesses loaded",TotalBusinesses);
    return 1;
}
You can put the query in OnGameModeInit after you connect to the database and delete LoadBizz(); (if there is any)
Reply
#4

You are the MAN! Very very thanks! ++ REP
only the icons (pickups) that no longer appear, because companies are being born after the functions are performed addstaticpickup and create3dtext = / have any idea how can I arrange this?


I did so to save: worked perfectly here.
pawn Код:
forward SaveBizz();
public SaveBizz()
{
    new rows, fields,TotalBusinesses;
    cache_get_data(rows, fields);
    while(TotalBusinesses < rows)
    {
        new Str[484];
        format(Str,231,"UPDATE `empresas` SET `Vendida`='%i',`Dono`='%s',`Mensagem`='%s',`Extorcao`='%s',`EntradaX`='%f',`EntradaY`='%f',`EntradaZ`='%f',",BizzInfo[TotalBusinesses][bOwned],BizzInfo[TotalBusinesses][bOwner],BizzInfo[TotalBusinesses][bMessage],
        BizzInfo[TotalBusinesses][bExtortion],BizzInfo[TotalBusinesses][bEntranceX],BizzInfo[TotalBusinesses][bEntranceY],BizzInfo[TotalBusinesses][bEntranceZ]);
        format(Str,484,"%s`SaidaX`='%f',`SaidaY`='%f',`SaidaZ`='%f',`LevelNecessario`='%i',`PrecoCompra`='%i',`EntradaCusto`='%i',`Till`='%i',`Trancada`='%i',`Interior`='%i' WHERE `ID`='%i'",Str,BizzInfo[TotalBusinesses][bExitX],BizzInfo[TotalBusinesses][bExitY],
        BizzInfo[TotalBusinesses][bExitZ],BizzInfo[TotalBusinesses][bLevelNeeded],BizzInfo[TotalBusinesses][bBuyPrice],BizzInfo[TotalBusinesses][bEntranceCost],BizzInfo[TotalBusinesses][bTill],BizzInfo[TotalBusinesses][bLocked],BizzInfo[TotalBusinesses][bInterior],TotalBusinesses);
        mysql_function_query(Connect, Str, false, "","");
        TotalBusinesses++;
    }
    printf("%d businesses saved",TotalBusinesses);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)