SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/07/2016, 08:18 PM   #1
wharlos
Huge Clucker
 
wharlos's Avatar
 
Join Date: Nov 2015
Location: Venezuela
Posts: 448
Reputation: 14
Default You can optimize this code?

I wonder if this code can be optimized?

PHP Code:
    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]); 
wharlos is offline   Reply With Quote
Old 03/07/2016, 08:21 PM   #2
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,526
Reputation: 554
Default Re: You can optimize this code?

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

Dirty, quick option:
http://forum.sa-mp.com/showthread.php?t=602923

pawn Code:
sscanf(componentes, "p<|>a<i>[13]", VehInfo[i][vComponentes]);
Misiur is offline   Reply With Quote
Old 03/07/2016, 08:23 PM   #3
wharlos
Huge Clucker
 
wharlos's Avatar
 
Join Date: Nov 2015
Location: Venezuela
Posts: 448
Reputation: 14
Default Respuesta: Re: You can optimize this code?

Quote:
Originally Posted by Misiur View Post
Harder, better option: Use normalized tables for components - do not store them in a single field!

Dirty, quick option:
http://forum.sa-mp.com/showthread.php?t=602923

pawn Code:
sscanf(componentes, "p<|>a<i>[13]", VehInfo[i][vComponentes]);
So I have to create 14 columns?
wharlos is offline   Reply With Quote
Old 03/07/2016, 08:32 PM   #4
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,083
Reputation: 2655
Default Re: You can optimize this code?

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: http://forum.sa-mp.com/showthread.php?t=420363
__________________
Vince is offline   Reply With Quote
Old 03/07/2016, 08:34 PM   #5
Stinged
High-roller
 
Join Date: Feb 2013
Posts: 1,575
Reputation: 187
Default Re: You can optimize this code?

http://forum.sa-mp.com/showthread.php?t=420363

EDIT: Damn it, didn't reload the page.. Sorry.
Stinged is offline   Reply With Quote
Old 03/07/2016, 08:49 PM   #6
wharlos
Huge Clucker
 
wharlos's Avatar
 
Join Date: Nov 2015
Location: Venezuela
Posts: 448
Reputation: 14
Default Respuesta: You can optimize this code?

I help with this is to save?

PHP Code:
    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 Code:
    mysql_format(mysqlquerysizeof(query), "UPDATE vehiculos SET vComponentes = '%s' WHERE vID = '%d'"componentesVehInfo[id][vID]);
    
mysql_tquery(mysqlquery); 
wharlos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
optimize code JoshNudock Scripting Help 4 22/06/2015 08:38 PM
Optimize code Elite1337 Scripting Help 1 14/01/2015 01:07 PM
Optimize this code... Baltimore Scripting Help 3 15/11/2014 08:45 PM
Help optimize this code Raefal Scripting Help 8 06/09/2014 09:09 AM
help me to optimize my code armyoftwo Help Archive 3 14/11/2010 11:19 AM


All times are GMT. The time now is 09:54 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.