Mysql Loading Help ! [+rep]
#1

Okay i have just made a simple system from the mailbox one , i made atm system all u do[/createatm-/removeatm]

and they work fine and if anyone /awithdraw and /adeposit besides it , it work but my main proplem that its saves fine in mysql database but it doesnt load.

PHP Code:
forward OnLoadATMS();
public 
OnLoadATMS()
{
    new 
string[512], i;
    new 
rowsfields;
    
cache_get_data(rowsfieldsMainPipeline);
    while(
i<rows)
    {
        for(new 
field;field<fields;field++)
        {
             
cache_get_row(ifieldstringMainPipeline);
            switch(
field)
            {
                case 
1ATM[i][atmVW] = strval(string);
                case 
2ATM[i][atmInt] = strval(string);
                case 
3ATM[i][atmModelz] = strval(string);
                case 
4ATM[i][atmPosX] = floatstr(string);
                case 
5ATM[i][atmPosY] = floatstr(string);
                case 
6ATM[i][atmPosZ] = floatstr(string);
                case 
7ATM[i][atmAngle] = floatstr(string);
            }
        }
        
RenderATM(i);
          
i++;
     }
    if(
0printf("[LoadATMS] %d atms rehashed/loaded."i);
    else 
printf("[LoadATMS] Failed to load any atms.");
    return 
1;

I 've used this ^ ^ ^ ^ but it didn't work then i used this

PHP Code:
forward OnLoadATMS();
public 
OnLoadATMS()
{
    new 
irowsfieldstmp[128];
    
cache_get_data(rowsfieldsMainPipeline);
    while(
rows)
    {
        
cache_get_field_content(i"VW"tmpMainPipeline); ATM[i][atmVW] = strval(tmp);
        
cache_get_field_content(i"Int"tmpMainPipeline); ATM[i][atmInt] = strval(tmp);
        
cache_get_field_content(i"Modelz"tmpMainPipeline); ATM[i][atmModelz] = strval(tmp);
        
cache_get_field_content(i"PosX"tmpMainPipeline); ATM[i][atmPosX] = floatstr(tmp);
        
cache_get_field_content(i"PosY"tmpMainPipeline); ATM[i][atmPosY] = floatstr(tmp);
        
cache_get_field_content(i"PosZ"tmpMainPipeline); ATM[i][atmPosZ] = floatstr(tmp);
        
cache_get_field_content(i"Angle"tmpMainPipeline); ATM[i][atmAngle] = floatstr(tmp);
    }
        
RenderATM(i);
          
i++;
    if(
0printf("[LoadATMS] %d houses rehashed/loaded."i);
    else 
printf("[LoadATMS] Failed to load any houses.");

But it also doesnt work i got no idea why it doesnt work


[Functions]

PHP Code:
stock SaveATM(id)
{
    new 
string[512];
    
format(stringsizeof(string), "UPDATE `atms` SET \
        `VW`=%d, \
        `Int`=%d, \
        `Modelz`=%d, \
        `PosX`=%f, \
        `PosY`=%f, \
        `PosZ`=%f, \
        `Angle`=%f WHERE `id`=%d"
,
        
ATM[id][atmVW],
        
ATM[id][atmInt],
        
ATM[id][atmModelz],
        
ATM[id][atmPosX],
        
ATM[id][atmPosY],
        
ATM[id][atmPosZ],
        
ATM[id][atmAngle],
        
id+1
    
); // Array starts from zero, MySQL starts at 1 (this is why we are adding one).
    
mysql_function_query(MainPipelinestringfalse"OnQueryFinish""i"SENDDATA_THREAD);

also
PHP Code:
stock RenderATM(id)
{
    
DestroyDynamicObject(ATM[id][atmObjectId]);
    
DestroyDynamic3DTextLabel(ATM[id][atmTextId]);
    if(
ATM[id][atmPosX] != 0.0)
    {
        new 
string[128];
        
ATM[id][atmObjectId] = CreateDynamicObject(2942ATM[id][atmPosX], ATM[id][atmPosY], ATM[id][atmPosZ], 0.00.0ATM[id][atmAngle], ATM[id][atmVW], ATM[id][atmInt], .streamdistance 100.0);
        
format(string,sizeof(string),"ATM (ID: %d)\nType /awithdraw or /adeposit to transfer cash."id);
        
ATM[id][atmTextId] = CreateDynamic3DTextLabel(stringCOLOR_YELLOWATM[id][atmPosX], ATM[id][atmPosY], ATM[id][atmPosZ] + 0.510.0, .worldid ATM[id][atmVW], .testlos 0, .streamdistance 25.0);
    }

and the enums

PHP Code:
enum atmInfo
{
    
atmVW,
    
atmInt,
    
atmModelz,
    
FloatatmPosX,
    
FloatatmPosY,
    
FloatatmPosZ,
    
FloatatmAngle,
    
atmObjectId,
    
Text3DatmTextId

Please HELP!! it doesnt load and when it saves it saves everything except "Modelz" modelz keeps 0 but i can set it easily.
Reply
#2

What I think :

- You don't need Mysql for these kind of things, MySql is good for accounts and similar things, because it's fast and safe, but SQL is hard to manipulate, because it's not an include / plugin, it's a language. So, I'd say check out y_ini / djson / ..., good for loading and saving similar data.
Reply
#3

Okay then , can you do me a favor and do the y_ini saving and loading with those enums please?

atmposx atmposz atmposy atmmodelz atmangle atmVW atmInt
Reply
#4

Well, if you want to manage atm's from let's say website, sql is a good choice (though it's not impossible with files, but a little inconvinient).

pawn Code:
while(i < rows)
    {
        cache_get_field_content(i, "VW", tmp, MainPipeline); ATM[i][atmVW] = strval(tmp);
        cache_get_field_content(i, "Int", tmp, MainPipeline); ATM[i][atmInt] = strval(tmp);
        cache_get_field_content(i, "Modelz", tmp, MainPipeline); ATM[i][atmModelz] = strval(tmp);
        cache_get_field_content(i, "PosX", tmp, MainPipeline); ATM[i][atmPosX] = floatstr(tmp);
        cache_get_field_content(i, "PosY", tmp, MainPipeline); ATM[i][atmPosY] = floatstr(tmp);
        cache_get_field_content(i, "PosZ", tmp, MainPipeline); ATM[i][atmPosZ] = floatstr(tmp);
        cache_get_field_content(i, "Angle", tmp, MainPipeline); ATM[i][atmAngle] = floatstr(tmp);
    }
        RenderATM(i);
          i++;
Put i++ and RenderATM inside the while, should work then.
Reply
#5

Also why aren't you using the natives cache_get_field_content_int() and cache_get_field_content_float()
Reply
#6

[QUOTE=Misiur;3400729]Well, if you want to manage atm's from let's say website, sql is a good choice (though it's not impossible with files, but a little inconvinient).

pawn Code:
while(i < rows)
    {
        cache_get_field_content(i, "VW", tmp, MainPipeline); ATM[i][atmVW] = strval(tmp);
        cache_get_field_content(i, "Int", tmp, MainPipeline); ATM[i][atmInt] = strval(tmp);
        cache_get_field_content(i, "Modelz", tmp, MainPipeline); ATM[i][atmModelz] = strval(tmp);
        cache_get_field_content(i, "PosX", tmp, MainPipeline); ATM[i][atmPosX] = floatstr(tmp);
        cache_get_field_content(i, "PosY", tmp, MainPipeline); ATM[i][atmPosY] = floatstr(tmp);
        cache_get_field_content(i, "PosZ", tmp, MainPipeline); ATM[i][atmPosZ] = floatstr(tmp);
        cache_get_field_content(i, "Angle", tmp, MainPipeline); ATM[i][atmAngle] = floatstr(tmp);
    }
        RenderATM(i);
          i++;
I've made it , it compilied with 0 warns and everything looks fine but when i restart the server i didn't see any atm and i did /gotoatm and it said
PHP Code:
    if(ATM[id][atmPosX] == 0.0) {
        return 
SendClientMessageEx(playeridCOLOR_GRAD2"No atms found with that ID."); 
and i refreashed the mysql and the pos.. changed when i /createatm that means that its saving fine but the loading is destroyed.

Loading ..

PHP Code:
stock LoadATMS()
{
    
printf("[LoadAtms] Loading data from database...");
    
mysql_function_query(MainPipeline"SELECT * FROM `atms`"true"OnLoadAtms""");

AND onloadatms

PHP Code:
forward OnLoadATMS();
public 
OnLoadATMS()
{
    new 
irowsfieldstmp[128];
    
cache_get_data(rowsfieldsMainPipeline);
    while(
rows)
    {
        
cache_get_field_content(i"VW"tmpMainPipeline); ATM[i][atmVW] = strval(tmp);
        
cache_get_field_content(i"Int"tmpMainPipeline); ATM[i][atmInt] = strval(tmp);
        
cache_get_field_content(i"Modelz"tmpMainPipeline); ATM[i][atmModelz] = strval(tmp);
        
cache_get_field_content(i"PosX"tmpMainPipeline); ATM[i][atmPosX] = floatstr(tmp);
        
cache_get_field_content(i"PosY"tmpMainPipeline); ATM[i][atmPosY] = floatstr(tmp);
        
cache_get_field_content(i"PosZ"tmpMainPipeline); ATM[i][atmPosZ] = floatstr(tmp);
        
cache_get_field_content(i"Angle"tmpMainPipeline); ATM[i][atmAngle] = floatstr(tmp);
        
RenderATM(i);
        
i++;
    }
    if(
0printf("[LoadATMS] %d houses rehashed/loaded."i);
    else 
printf("[LoadATMS] Failed to load any houses.");

Reply
#7

Do you see "[LoadATMS] X houses rehashed/loaded." in server log? Also apply what CuervO said:
pawn Code:
forward OnLoadATMS();
public OnLoadATMS()
{
    new i, rows, fields;
    cache_get_data(rows, fields, MainPipeline);

    while(i < rows)
    {
        ATM[i][atmVW] = cache_get_field_content_int(i, "VW", MainPipeline);
        ATM[i][atmInt] = cache_get_field_content_int(i, "Int", MainPipeline);
        ATM[i][atmModelz] = cache_get_field_content_int(i, "Modelz", MainPipeline);
        ATM[i][atmPosX] = cache_get_field_content_float(i, "PosX", MainPipeline);
        ATM[i][atmPosY] = cache_get_field_content_float(i, "PosY", MainPipeline);
        ATM[i][atmPosZ] = cache_get_field_content_float(i, "PosZ", MainPipeline);
        ATM[i][atmAngle] = cache_get_field_content_float(i, "Angle", MainPipeline);
        RenderATM(i);
        i++;
    }
    if(i > 0) printf("[LoadATMS] %d houses rehashed/loaded.", i);
    else printf("[LoadATMS] Failed to load any houses.");
}
Reply
#8

Quote:
Originally Posted by CuervO
View Post
Also why aren't you using the natives cache_get_field_content_int() and cache_get_field_content_float()
I am not good in MySQL do u mind u changing the natives for me please?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)