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 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        for(new 
1rows && MAX_FACTORIESi++)
        {
            
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 
1MAX_FACTORIESx++) {
        
mysql_format(mysqlquerysizeof(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 0rows && MAX_FACTORIESi++) 
PHP код:
for(new 0MAX_FACTORIESx++) 
Reply
#3

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

PHP код:
for(new 0rows && MAX_FACTORIESi++) 
PHP код:
for(new 0MAX_FACTORIESx++) 
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] [DEBUGCalling callback "OnFactoryLoad"..
[
04:02:30] [DEBUGcache_get_data connection1
[04:02:30] [DEBUGcache_get_field_content_int row0field_name"ID"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'0'field"ID"data"1"
[04:02:30] [DEBUGcache_get_field_content_int row0field_name"Resources"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'0'field"Resources"data"NULL"
[04:02:30] [ERRORcache_get_field_content_int invalid datatype
[04:02:30] [DEBUGcache_get_field_content_int row1field_name"ID"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'1'field"ID"data"2"
[04:02:30] [DEBUGcache_get_field_content_int row1field_name"Resources"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'1'field"Resources"data"6520"
[04:02:30] [DEBUGcache_get_field_content_int row2field_name"ID"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'2'field"ID"data"3"
[04:02:30] [DEBUGcache_get_field_content_int row2field_name"Resources"connection1
[04:02:30] [DEBUGCMySQLResult::GetRowDataByName row'2'field"Resources"data"3000"
[04:02:30] [DEBUGcache_get_field_content_int row3field_name"ID"connection
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:19UPDATE `factoriesSET `Resources`=500.0 WHERE `ID`=1
[04:14:19UPDATE `factoriesSET `Resources`=6520.0 WHERE `ID`=2
[04:14:19UPDATE `factoriesSET `Resources`=3000.0 WHERE `ID`=
It prints as it should be but still not saving the ID 1 at all




EDIT 2: new SQL log
PHP код:
[04:28:15] [DEBUGCalling callback "OnFactoryLoad"..
[
04:28:15] [DEBUGcache_get_data connection1
[04:28:15] [DEBUGcache_get_field_content_int row0field_name"ID"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'0'field"ID"data"1"
[04:28:15] [DEBUGcache_get_field_content_float row0field_name"Resources"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'0'field"Resources"data"000000000000"
[04:28:15] [DEBUGcache_get_field_content_int row1field_name"ID"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'1'field"ID"data"2"
[04:28:15] [DEBUGcache_get_field_content_float row1field_name"Resources"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'1'field"Resources"data"000000006520"
[04:28:15] [DEBUGcache_get_field_content_int row2field_name"ID"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'2'field"ID"data"3"
[04:28:15] [DEBUGcache_get_field_content_float row2field_name"Resources"connection1
[04:28:15] [DEBUGCMySQLResult::GetRowDataByName row'2'field"Resources"data"000000003000" 
Reply
#6

PHP код:
[04:02:30] [DEBUGCMySQLResult::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] [DEBUGCMySQLResult::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` (
    `
IDINT(10NOT NULL AUTO_INCREMENT,
    `
NameVARCHAR(50NULL DEFAULT NULL,
    `
ResourcesFLOAT 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 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        for(new 
1rows && MAX_FACTORIESi++)
        {
            
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 
1MAX_FACTORIESx++) {
        
mysql_format(mysqlquerysizeof(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(mysqlquerysizeof(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(mysqlquerysizeof(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: 2 Guest(s)