AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to save arrays to mysql (https://forums.alliedmods.net/showthread.php?t=184413)

DoviuX 05-05-2012 04:05

How to save arrays to mysql
 
How to save these arrays or variables into mysql ?

Is it something like this ?


PHP Code:

p_achieviments33 ][ MAXACHIEVIMENTS ], p_kills33 ][ MAXACHIEVIMENTS ], 
achvi_name33 ][ MAXACHIEVIMENTS ];

    new 
szAuth33 ];
    new 
szKey64 ];

    
get_user_ipidszAuth charsmaxszAuth ), 1);
    
formatexszKey 63 "%s-IP" szAuth );
    static 
szQuery128 ]; 
    
formatexszQuery127"INSERT INTO `achieviment_table` ( `player_id`, `achieviment_name`, `achieviment_id` ) VALUES ( '%s', '%s', '%d' );"szAuth achvi_nameid ][ ], p_achievimentsid ][ ] ); 


claudiuhks 05-05-2012 04:56

Re: How to save arrays to mysql
 
PHP Code:

// NUMERIC
INSERT INTO MyTable MyFirstRowMySecondRow VALUES 1)
// INSERT INTO Ach ( Kills, Deaths ) VALUES ( %d, %d )

// TEXT
INSERT INTO MyTable MyFirstRowMySecondRow VALUES 'abc''lmn' )
// INSERT INTO Ach ( Name, Steam ) VALUES ( '%s', '%s' )

// FUNCTIONS
INSERT INTO MyTable MyFirstRow VALUES unix_timestampnow( ) ) ) // TIME ELAPSED IN SECONDS SINCE UNIX EPOCH ( JAN 01 1970 ) 

Please make sure your szQuery string has enough characters to handle your whole query. I recommend 256 or 512 cells instead.

DoviuX 05-05-2012 05:04

Re: How to save arrays to mysql
 
Thanks, and will it make achieviments not into one every time but make new or change the existing ones ?
Becouse I have many achieviments and I want that it showed in the website like steams achieviments.

claudiuhks 05-05-2012 05:13

Re: How to save arrays to mysql
 
Quote:

Originally Posted by DoviuX (Post 1702468)
Thanks, and will it make achieviments not into one every time but make new or change the existing ones ?
Becouse I have many achieviments and I want that it showed in the website like steams achieviments.

I don't understand. What do you mean with and will it make achieviments not into one every time but make new or change the existing ones?

DoviuX 05-05-2012 05:25

Re: How to save arrays to mysql
 
I show you an example what i want to do:
Code:

  PlayerIp( or steamid ) - **.**.**.**
  AchievimentName - Zombie Killer
  AchievimentId - 1

  PlayerIp( or steamid ) - **.**.**.**
  AchievimentName - Zombie Massacer
  AchievimentId - 2

  PlayerIp( or steamid ) - **.**.**.**
  AchievimentName - Zombie Destroyer
  AchievimentId - 3

I need that this would be save in mysql, i'am asking by you're gaved code does it make like I showed you now ?

claudiuhks 05-05-2012 06:22

Re: How to save arrays to mysql
 
PHP Code:

enum Achievements ( <<= )
{
  
ACHIEVEMENT_ZOMBIE_HUNTER 1,
  
ACHIEVEMENT_ZOMBIE_SACRIFICER,
  
ACHIEVEMENT_ZOMBIE_ETC
};

new 
g_iAchievements33 ];

/*
  Player Steam - '%s' - g_cSteam[ 33 ][ 24 ];
  Player IP - '%s' - g_cIP[ 33 ][ 24 ];
  Player Achievements - '%d' - g_iAchievements[ 33 ];
*/

// At plugin attaching
CREATE TABLE IF NOT EXISTS achievements steam TEXTaddress TEXTachievements_list NUMERIC )

// When client joins
SELECT achievements_list FROM achievements WHERE steam '%playersteam%'

// When the function for above query is executed
// If we have a row
g_iAchievementsThisPlayer ] = SQL_ReadResulthQuery);

// Else, if we don't have rows
g_iAchievementsThisPlayer ] = 0;

INSERT INTO achievements VALUES '%playersteam%''%playerip%')

// When a player receive an achievement
if( !( g_iAchivementsThisPlayer ] & ACHIEVEMENT_ZOMBIE_HUNTER ) ) {
  
g_iAchievementsThisPlayer ] |= ACHIEVEMENT_ZOMBIE_HUNTER;

  
UPDATE TABLE achievements SET achievements_list = %playerachievementsWHERE steam '%playersteam%'




All times are GMT -4. The time now is 00:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.