02.08.2014, 18:43
There is a conflict with those two caches. The cached result generated in your helper function (GetResourceName) overwrites the active cache you generated at the top of your command.
You also don't need two different connections for this, just make sure the caches don't overwrite themselves.
Oh, and you forgot to delete the cache. Here are some more informations on mysql_query.
Here's the fixed version of your code:
You also don't need two different connections for this, just make sure the caches don't overwrite themselves.
Oh, and you forgot to delete the cache. Here are some more informations on mysql_query.
Here's the fixed version of your code:
Code:
COMMAND:bstorage(playerid, params[]) { new tBID, tRID, query[100], string[256]; if(sscanf(params, "d", tBID)){ return SendClientMessage(playerid, -1, "USAGE:\"/bstorage [Business IDl]\""); } mysql_format(mysql, query, sizeof(query), "SELECT * from `businesses_storage` where `BID` = '%d'", tBID); new Cache:res1 = mysql_query(mysql, query); //res1 is now the active cache here for(new i = 0; i < cache_num_rows(); i++) { tRID = cache_get_field_content_int(i, "RID"); format(string, sizeof(string), "RID: %d - %s", tRID, GetResourceName(tRID)); SCM(playerid, -1, string); //the cache in your function "GetResourceName" overwrote our "res1" cache, //we need to manually set "res1" as the active cache now cache_set_active(res1); } cache_delete(res1); return 1; } stock GetResourceName(RID) { new query[100], tempName[24]; mysql_format(mysql, query, sizeof(query), "SELECT `Name` FROM `resources` WHERE `ID` = '%d'", RID); new Cache:result = mysql_query(mysql, query); //result is now the active cache here, overwriting any previously active cache if(cache_num_rows()) { cache_get_field_content(0, "Name", tempName); } cache_delete(result); //result has been deleted, there is now no active cache return tempName; }