MySQL loading problem
#1

My code is:
Код:
//This is under OnGameModeInit
mysql_function_query(Connection,"SELECT * FROM houses",false,"LoadHouses","i",playerid);
//The public
public LoadHouses()
{
	new string[128];
    static rows,fields;
	cache_get_data(rows, fields, Connection);
	for(new i = 0; i < rows; i++)
	{
	    Houses++;
	    cache_get_field_content(0,"Owner",hInfo[i][hOwner],Connection,64);
        hInfo[i][hIndex] = cache_get_field_content_int(0,"ID");
	    hInfo[i][hPrice] = cache_get_field_content_int(0,"Price");
	    hInfo[i][hPos][0] = cache_get_field_content_float(0,"X");
	    hInfo[i][hPos][1] = cache_get_field_content_float(0,"Y");
	    hInfo[i][hPos][2] = cache_get_field_content_float(0,"Z");
    }
    format(string,sizeof(string),"Loaded %d houses",Houses);
    print(string);
    Housess = Houses;
    SpawnHouses();
    return 1;
}
//SpawnHouses
stock SpawnHouses()
{
	new string[128];
	while(Housess >= 1)
	{
    	hInfo[Housess][hOne] = CreateDynamicPickup(1273, 1, hInfo[Housess][hPos][0], hInfo[Housess][hPos][1], hInfo[Housess][hPos][2], 0);
    	format(string, sizeof(string), "House owner:%s", hInfo[Housess][hOwner]);
		hInfo[Housess][hTwo] = CreateDynamic3DTextLabel(string, COLOR_WHITE, hInfo[Housess][hPos][0], hInfo[Housess][hPos][1], hInfo[Housess][hPos][2], 0, 0, 0);
    	Housess--;
    }
}
This prints the right amount of houses in my database but doesnt spawn pickups and when i use my command /gotohouse whatever id of house i type it teleports me to one position, so it loads all houses on the same position.
Reply
#2

... That's because you only load row 0 data for all rows =m=

Change :
pawn Код:
cache_get_field_content(0,"Owner",hInfo[i][hOwner],Connection,64);
        hInfo[i][hIndex] = cache_get_field_content_int(0,"ID");
        hInfo[i][hPrice] = cache_get_field_content_int(0,"Price");
        hInfo[i][hPos][0] = cache_get_field_content_float(0,"X");
        hInfo[i][hPos][1] = cache_get_field_content_float(0,"Y");
        hInfo[i][hPos][2] = cache_get_field_content_float(0,"Z");
To :
pawn Код:
cache_get_field_content(i,"Owner",hInfo[i][hOwner],Connection,64);
        hInfo[i][hIndex] = cache_get_field_content_int(i,"ID");
        hInfo[i][hPrice] = cache_get_field_content_int(i,"Price");
        hInfo[i][hPos][0] = cache_get_field_content_float(i,"X");
        hInfo[i][hPos][1] = cache_get_field_content_float(i,"Y");
        hInfo[i][hPos][2] = cache_get_field_content_float(i,"Z");
Reply
#3

You're not loading the data correctly.
Reply
#4

There are few issues, the one rickisme mentioned about the rows. You were actually retrieving only the first row and not the rest - that's what the loop is for!
In mysql_function_query, you need to set cache to true and you don't need any extra argument such as playerid which is undefined symbol in OnGameModeInit anyway.
You don't need a second loop either.

PHP код:
//This is under OnGameModeInit
mysql_function_query(Connection,"SELECT * FROM houses",true,"LoadHouses","");
public 
LoadHouses()
{
    new 
string[40] = "House owner:",fields;
    
cache_get_data(HousessfieldsConnection);
    
    for(new 
0Housessi++)
    {
        
cache_get_field_content(i,"Owner",hInfo[i][hOwner],Connection,64);
        
hInfo[i][hIndex] = cache_get_field_content_int(i,"ID");
        
hInfo[i][hPrice] = cache_get_field_content_int(i,"Price");
        
hInfo[i][hPos][0] = cache_get_field_content_float(i,"X");
        
hInfo[i][hPos][1] = cache_get_field_content_float(i,"Y");
        
hInfo[i][hPos][2] = cache_get_field_content_float(i,"Z");
        
        
hInfo[i][hOne] = CreateDynamicPickup(12731hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2], 0);
        
strcat(stringhInfo[i][hOwner], sizeof (string));
        
hInfo[i][hTwo] = CreateDynamic3DTextLabel(stringCOLOR_WHITEhInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2], 000);
    }
    
printf("Loaded %d houses",Housess);
    return 
1;

Reply
#5

Then how to load player account ? ?
Код:
public LoadAccount(playerid)
{
    cache_get_field_content(0,"Password",pInfo[playerid][Password]);
    pInfo[playerid][Level] = cache_get_field_content_int(0,"Level");
    pInfo[playerid][Hours] = cache_get_field_content_int(0,"Hours");
    pInfo[playerid][Minutes] = cache_get_field_content_int(0,"Minutes");

    return 1;
}
Reply
#6

Loading accounts, This might help you: https://sampforum.blast.hk/showthread.php?tid=485633
Reply
#7

Quote:
Originally Posted by SandKing94
Посмотреть сообщение
Then how to load player account ? ?
Код:
public LoadAccount(playerid)
{
    cache_get_field_content(0,"Password",pInfo[playerid][Password]);
    pInfo[playerid][Level] = cache_get_field_content_int(0,"Level");
    pInfo[playerid][Hours] = cache_get_field_content_int(0,"Hours");
    pInfo[playerid][Minutes] = cache_get_field_content_int(0,"Minutes");

    return 1;
}
This code is valid.

The first parameter of cache_get_field_content is the row index(which start at 0). So it's okay to use 0 if you only load 1 row(like you do here).

But if you select multiple rows, you will need to loop through all of them because index 0 is merely the first row, that second one will be at index 1 and so on.
Reply
#8

Stev already linked you to a tutorial for what you asked for but just a note on your current code.

When using cache_get_field_content function with enum-array, you need to add the max size for it to work.
Reply
#9

So i have to make it like that ?
Код:
cache_get_field_content(0,"Password",pInfo[playerid][Password]);
    pInfo[playerid][Level] = cache_get_field_content_int(1,"Level");
    pInfo[playerid][Hours] = cache_get_field_content_int(2,"Hours");
    pInfo[playerid][Minutes] = cache_get_field_content_int(3,"Minutes");
Reply
#10

No, dont mix columns and rows.

Your table probably looks like somewhat like this:

Код:
Password | Level | Hours | Minutes
Those are columns, each row has(most likely) a value in it. There can be multiple rows. I understand that you select soemthing like WHERE name is equal to the player name. So probably you will only have one row here. That means all indexes will be 0.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)