[MYSQL] More efficient way?
#1

Hey guys i did this little system that saves guns, and ammo when you disconnect, but my MySQL script got kind of funky:

pawn Код:
format(MySQLQuery, sizeof(MySQLQuery), "UPDATE vartotojai SET Ginklas1=%i, Ginklas1a=%i, Ginklas2=%i, Ginklas2a=%i, Ginklas3=%i, Ginklas3a=%i, Ginklas4=%i, Ginklas4a=%i WHERE Vardas='%s'", WeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a], WeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a],WeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a], WeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a], pname);
            mysql_query(MySQLQuery);
            format(MySQLQuery, sizeof(MySQLQuery), "UPDATE vartotojai SET Ginklas5=%i, Ginklas5a=%i, Ginklas6=%i, Ginklas6a=%i, Ginklas7=%i, Ginklas7a=%i, Ginklas8=%i, Ginklas8a=%i WHERE Vardas='%s'", WeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a], WeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a],WeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a], WeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a], pname);
            mysql_query(MySQLQuery);
            format(MySQLQuery, sizeof(MySQLQuery), "UPDATE vartotojai SET Ginklas9=%i, Ginklas9a=%i, Ginklas10=%i, Ginklas10a=%i, Ginklas11=%i, Ginklas11a=%i, Ginklas12=%i, Ginklas12a=%i WHERE Vardas='%s'", WeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a], WeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a],WeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a], WeaponInfo[playerid][Weapon12], WeaponInfo[playerid][Weapon12a], pname);
            mysql_query(MySQLQuery);
This is to just save all the guns, and i think it is unecessary for three querys. Does anyone know of more efficient way? If so can you give me an example?
Reply
#2

To be honest.. One query should be enough. Make it so it gets the ammo amount and updates it with that ammo. Then once you log in make sure it reads from the database to give that player that ammo amount and gun.
Reply
#3

Foreign keys! Learn about them.
https://sampforum.blast.hk/showthread.php?tid=420363
Reply
#4

A bit more specific to weapons: https://sampforum.blast.hk/showthread.php?tid=505081
Reply
#5

Thank you guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)