MySQL query issue
#3

Quote:
Originally Posted by whadez
View Post
Code:
function:Query_LoadInvItems(playerid, invid) 
{ 
    new rows, fields;  
    cache_get_row_count(rows);  
    cache_get_field_count(fields); 
     
    for (new i = 0; i < rows; i++) 
    { 
        cache_get_value_name_int(i, "items_id", InvItems[i][iItemsID]); 
        cache_get_value_name_int(i, "char_id", InvItems[i][iCharID]); 
        cache_get_value_name_int(i, "modelid", InvItems[i][iModelID]); 
        cache_get_value_name(i, "item_name", InvItems[i][iItemName], 50); 
        cache_get_value_name_int(i, "item_amount", InvItems[i][iItemAmount]); 
		
    } 
}  

It should be (If you have no clue how to assign the right index, make a 3d array [just use my version below]):

cache_get_value_name_int(i, "items_id", InvItems[playerid][i][iItemsID]); 
cache_get_value_name_int(i, "char_id", InvItems[playerid][i][iCharID]); 
cache_get_value_name_int(i, "modelid", InvItems[playerid][i][iModelID]); 
cache_get_value_name(i, "item_name", InvItems[playerid][i][iItemName], 50); 
cache_get_value_name_int(i, "item_amount", InvItems[playerid][i][iItemAmount]); 

But you should use (better version):

cache_get_value_name_int(i, "items_id", InvItems[playerid*MAX_ITEM+i][iItemsID]); 
cache_get_value_name_int(i, "char_id", InvItems[playerid*MAX_ITEM+i][iCharID]); 
cache_get_value_name_int(i, "modelid", InvItems[playerid*MAX_ITEM+i][iModelID]); 
cache_get_value_name(i, "item_name", InvItems[playerid*MAX_ITEM+i][iItemName], 50); 
cache_get_value_name_int(i, "item_amount", InvItems[playerid*MAX_ITEM+i][iItemAmount]); 

// Explaination:

// Loop [player id: 0]
InvItems[playerid * 20 + i (0)][variable]
InvItems[playerid * 20 + i (1)][variable]
InvItems[playerid * 20 + i (2)][variable]

// Loop [player id: 1]
InvItems[playerid * 20 + i (20)][variable]
InvItems[playerid * 20 + i (21)][variable]
InvItems[playerid * 20 + i (22)][variable]

// To test out the values

GetPlayerItems(playerid) {
	new i=-1, tempStr[256];
	for(;++i<MAX_ITEMS;) {
		format(tempStr, sizeof tempStr, "Assigned Index: %i | iItemsID: %i", (playerid * MAX_ITEMS + i), InvItems[playerid*MAX_ITEM+i][iItemsID]);
	}
	SendClientMessage(playerid, -1, tempStr);
	return 1;
}

Change the array size to:
InvItems[MAX_ITEMS * MAX_PLAYERS][ENUM]
It seems that it is no longer fetching the data from the database using this. It's setting everything to "0".

Well, it's fetching it, just not setting it to the enums.
Reply


Messages In This Thread
MySQL query issue - by AlphaPac - 23.09.2017, 17:28
Re: MySQL query issue - by whadez - 23.09.2017, 17:40
Re: MySQL query issue - by AlphaPac - 23.09.2017, 18:15

Forum Jump:


Users browsing this thread: 1 Guest(s)