SA-MP Forums Archive
You can optimize this code? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: You can optimize this code? (/showthread.php?tid=611222)



You can optimize this code? - wharlos - 03.07.2016

I wonder if this code can be optimized?

PHP код:
    new componentes[70]; 
    
cache_get_field_content(0"vComponentes"componentesmysqlsizeof(componentes)); 
    
sscanf(componentes"p<|>iiiiiiiiiiiiii"
    
VehInfo[i][vComponentes][0], VehInfo[i][vComponentes][1], VehInfo[i][vComponentes][2], VehInfo[i][vComponentes][3], VehInfo[i][vComponentes][4], 
    
VehInfo[i][vComponentes][5], VehInfo[i][vComponentes][6], VehInfo[i][vComponentes][7], VehInfo[i][vComponentes][8], VehInfo[i][vComponentes][9], 
    
VehInfo[i][vComponentes][10], VehInfo[i][vComponentes][11], VehInfo[i][vComponentes][12], VehInfo[i][vComponentes][13]); 



Re: You can optimize this code? - Misiur - 03.07.2016

Harder, better option: Use normalized tables for components - do not store them in a single field!

Dirty, quick option:
https://sampforum.blast.hk/showthread.php?tid=602923

pawn Код:
sscanf(componentes, "p<|>a<i>[13]", VehInfo[i][vComponentes]);



Respuesta: Re: You can optimize this code? - wharlos - 03.07.2016

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Harder, better option: Use normalized tables for components - do not store them in a single field!

Dirty, quick option:
https://sampforum.blast.hk/showthread.php?tid=602923

pawn Код:
sscanf(componentes, "p<|>a<i>[13]", VehInfo[i][vComponentes]);
So I have to create 14 columns?


Re: You can optimize this code? - Vince - 03.07.2016

Basic normalization guidelines state that you shouldn't store more than one natural value in a single field. But no, you don't have to create 14 columns. You should create 14 rows in a new table. Check this out: https://sampforum.blast.hk/showthread.php?tid=420363


Re: You can optimize this code? - Stinged - 03.07.2016

https://sampforum.blast.hk/showthread.php?tid=420363

EDIT: Damn it, didn't reload the page.. Sorry.


Respuesta: You can optimize this code? - wharlos - 03.07.2016

I help with this is to save?

PHP код:
    new componentes[128];
    
format(componentessizeof(componentes), "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d",
    
VehInfo[id][vComponentes][0], VehInfo[id][vComponentes][1], VehInfo[id][vComponentes][2], VehInfo[id][vComponentes][3], VehInfo[id][vComponentes][4],
    
VehInfo[id][vComponentes][5], VehInfo[id][vComponentes][6], VehInfo[id][vComponentes][7], VehInfo[id][vComponentes][8], VehInfo[id][vComponentes][9],
    
VehInfo[id][vComponentes][10], VehInfo[id][vComponentes][11], VehInfo[id][vComponentes][12], VehInfo[id][vComponentes][13]); 
PHP код:
    mysql_format(mysqlquerysizeof(query), "UPDATE vehiculos SET vComponentes = '%s' WHERE vID = '%d'"componentesVehInfo[id][vID]);
    
mysql_tquery(mysqlquery);