SQL & loop problem
#1

Alright so the problem is quite simple, it saves factory data for 2-3 but not for 1

PHP код:
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;
} 
Reply
#2

Shouldn't the loops start at 0?

PHP код:
for(new i = 0; i < rows && i < MAX_FACTORIES; i++) 
PHP код:
for(new x = 0; x < MAX_FACTORIES; x++) 
Reply
#3

Quote:
Originally Posted by zPain
Посмотреть сообщение
Shouldn't the loops start at 0?

PHP код:
for(new i = 0; i < rows && i < MAX_FACTORIES; i++) 
PHP код:
for(new x = 0; x < MAX_FACTORIES; x++) 
nah, the problem aint that, I dont want of it to start at 0. Basically the IDS are going from 1 inside the setup I made.
Also tried to test with 0 for fun, still nothing
Reply
#4

Regardless, if you start fetching the results from row 1, you'll be actually starting from the second row.

Edit: Did you notice that the query wasn't submitted in the SaveFactories function?
Reply
#5

Yeah but still row 1 is set as NULL

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 
I fixed the prob with invalid datatype
I was using int instead of float but still the problem remains





EDIT: SA:MP log
PHP код:
[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 
It prints as it should be but still not saving the ID 1 at all




EDIT 2: new SQL log
PHP код:
[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" 
Reply
#6

PHP код:
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "ID", data: "1" 
I still think the problem is about the index (0-1) matter. Otherwise, you should share more of the source code with us.
Reply
#7

Quote:
Originally Posted by zPain
Посмотреть сообщение
PHP код:
[04:02:30] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "ID", data: "1" 
I still think the problem is about the index (0-1) matter. Otherwise, you should share more of the source code with us.
Well that is the actual full code mate, nothing besides it really.
This is the only thing left to share to be honest
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
; 
Reply
#8

You're overlooking the fact that the query is not even sent to the server. You're formatting it, but it's not actually being sent.
Reply
#9

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Alright so the problem is quite simple, it saves factory data for 2-3 but not for 1

PHP код:
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;
} 
How you demand the table to be updated when you format but doesn't send the query?
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); 
Reply
#10

Quote:
Originally Posted by vassilis
Посмотреть сообщение
How you demand the table to be updated when you format but doesn't send the query?
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); 
I havent included this part
PHP код:
mysql_tquery(mysql, "SELECT * FROM `factories`", "OnFactoryLoad", ""); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)