public OnFactoryLoad()
{
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
for(new i = 1; i < rows && i < MAX_FACTORIES; i++)
{
FactoryData[i][FactoryID] = cache_get_field_content_int(i,"ID");
FactoryData[i][FactoryResources] = cache_get_field_content_int(i,"Resources");
}
}
return true;
}
SaveFactories() {
new query[128];
for(new x = 1; x < MAX_FACTORIES; x++) {
mysql_format(mysql, query, sizeof(query), "UPDATE `factories` SET `Resources`=%f WHERE `ID`=%d",\
FactoryData[x][FactoryResources],FactoryData[x][FactoryID]);
}
return true;
}
CMD:test(playerid,params[]) {
FactoryData[1][FactoryResources] = 500;
FactoryData[2][FactoryResources] = 6520;
FactoryData[3][FactoryResources] = 3000;
return true;
}
for(new i = 0; i < rows && i < MAX_FACTORIES; i++)
for(new x = 0; x < MAX_FACTORIES; x++)
Shouldn't the loops start at 0?
PHP код:
PHP код:
|
[04:02:30] [DEBUG] Calling callback "OnFactoryLoad"..
[04:02:30] [DEBUG] cache_get_data - connection: 1
[04:02:30] [DEBUG] cache_get_field_content_int - row: 0, field_name: "ID", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "ID", data: "1"
[04:02:30] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Resources", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Resources", data: "NULL"
[04:02:30] [ERROR] cache_get_field_content_int - invalid datatype
[04:02:30] [DEBUG] cache_get_field_content_int - row: 1, field_name: "ID", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "ID", data: "2"
[04:02:30] [DEBUG] cache_get_field_content_int - row: 1, field_name: "Resources", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "Resources", data: "6520"
[04:02:30] [DEBUG] cache_get_field_content_int - row: 2, field_name: "ID", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "ID", data: "3"
[04:02:30] [DEBUG] cache_get_field_content_int - row: 2, field_name: "Resources", connection: 1
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "Resources", data: "3000"
[04:02:30] [DEBUG] cache_get_field_content_int - row: 3, field_name: "ID", connection: 1
[04:14:19] UPDATE `factories` SET `Resources`=500.0 WHERE `ID`=1
[04:14:19] UPDATE `factories` SET `Resources`=6520.0 WHERE `ID`=2
[04:14:19] UPDATE `factories` SET `Resources`=3000.0 WHERE `ID`=3
[04:28:15] [DEBUG] Calling callback "OnFactoryLoad"..
[04:28:15] [DEBUG] cache_get_data - connection: 1
[04:28:15] [DEBUG] cache_get_field_content_int - row: 0, field_name: "ID", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "ID", data: "1"
[04:28:15] [DEBUG] cache_get_field_content_float - row: 0, field_name: "Resources", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Resources", data: "000000000000"
[04:28:15] [DEBUG] cache_get_field_content_int - row: 1, field_name: "ID", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "ID", data: "2"
[04:28:15] [DEBUG] cache_get_field_content_float - row: 1, field_name: "Resources", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '1', field: "Resources", data: "000000006520"
[04:28:15] [DEBUG] cache_get_field_content_int - row: 2, field_name: "ID", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "ID", data: "3"
[04:28:15] [DEBUG] cache_get_field_content_float - row: 2, field_name: "Resources", connection: 1
[04:28:15] [DEBUG] CMySQLResult::GetRowDataByName - row: '2', field: "Resources", data: "000000003000"
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "ID", data: "1"
PHP код:
|
CREATE TABLE `factories` (
`ID` INT(10) NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(50) NULL DEFAULT NULL,
`Resources` FLOAT UNSIGNED ZEROFILL NULL DEFAULT '000000000000',
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=11
;
Alright so the problem is quite simple, it saves factory data for 2-3 but not for 1
PHP код:
|
mysql_format(mysql, query, sizeof(query), "UPDATE `factories` SET `Resources`=%f WHERE `ID`=%d",\
FactoryData[x][FactoryResources],FactoryData[x][FactoryID]);
mysql_tquery(mysql,query);
How you demand the table to be updated when you format but doesn't send the query?
PHP код:
|
mysql_tquery(mysql, "SELECT * FROM `factories`", "OnFactoryLoad", "");