AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   saving via sql (https://forums.alliedmods.net/showthread.php?t=155198)

tuty 04-18-2011 14:32

saving via sql
 
i have something like this

PHP Code:

enum _:ilist
{
    
list1,
    
list2,
    
list3
};

new const 
gListnameilist ][ ] =
{
    
"list1",
    
"list2",
    
"list3"
};

new 
gPlayerListData33 ][ ilist ]; 

i was wondering how to save all the data into a sql table with an loop ?
on webpage should be something like:arrow:

"list name 1" "player data for listname1"

etc

Exolent[jNr] 04-18-2011 21:24

Re: saving via sql
 
You would need a table like this:
- listname VARCHAR(10) NOT NULL (change 10 to however long you may need the name)
- listdata INT(11) NOT NULL (assumed an int based on the global variable)
- authid VARCHAR(35) NOT NULL
- PRIMARY KEY(listname, authid)

Then you can do this:
Code:
new szAuthID[ 35 ]; get_user_authid( iPlayer, szAuthID, charsmax( szAuthID ) ); new Handle:hQuery; for( new i; i < ilist; i++ ) {     hQuery = SQL_PrepareQuery( /* connection */,\         "INSERT INTO table \         (listname, listdata, authid) \         VALUES \         (^"%s^", %d, ^"%s^") \         ON DUPLICATE KEY UPDATE \         listdata = %d;",\         gListname[ i ], gPlayerListData[ iPlayer ][ i ], szAuthID, gPlayerListData[ iPlayer ][ i ] );         // execute query }

tuty 04-19-2011 05:22

Re: saving via sql
 
i was expecting to you to answer, thanks


since i suck on sql, how to retrieve the data with this way?

Exolent[jNr] 04-20-2011 14:19

Re: saving via sql
 
You can use a trie to save the list name associated to its constant.

Then when you load data from the player, check the list name to the constant using the trie, then save the listdata from the table into the array.


All times are GMT -4. The time now is 19:47.

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