Raised This Month: $ Target: $400
 0% 

if sql table ENTERY exist olny Update else insert - how to do this


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-18-2007 , 11:53   if sql table ENTERY exist olny Update else insert - how to do this
Reply With Quote #1

Hello,
i get here very usefull help.

Now i get a new Problem. Frist i wanna say that i am a
beginner in this scripting language.

Problem:
now the server olny update the enterys if the server is already in the Table (i added it manual) (See picture 1).
The Updateing function works perfecly thanks pRED* | NZ he helpt me very very mutch.



Now i olny need a if function and here is the problem.
I tried many thinks but i get everytime the error must be indexed or someting else.

Maybe somebody knows how this if funktion have to look like.

here is my idear, but i am unable to comlile it...(compile errors)
I am sure thats there exist a easyer way to make ti work.

My try: (as ID i use the Server IP because its never Change):

Code:
public write() { 
 new Server[200];
 get_cvar_string("net_address",Server,200);
 new Sql:mysql = dbi_connect("******", "******+", "********", "zbk")
 //Do a select query 
 new Result:res = dbi_query(mysql,"SELECT Server FROM zbkcommunity WHERE Server=^"%s^"",Server")
 //If the query is less than or equal to RESULT_FAILED, you got an invalid result and can't do anything with it.
 if (res <= RESULT_FAILED) 
 {
 new err[255]
 new errNum = dbi_error(mysql, err, 254)
 server_print("error3: %s|%d", err, errNum)
 return 1
 }
 //Loop through the result set 
 if (res && dbi_nextrow(res)>0) 
 {
 new exist[32]
 //Get the column/field called "keyname" from the result set
 dbi_result(res, "Server", exist, 31)
 // Now i have the Server saved in exist
 //Now i try to do a if command but this isnt work, dont know why, tried it many times
 new myserverip[200];
 get_cvar_string("net_address",myserverip,200);
 if (myserverip = exist) {
 //the server entery already exist...now i olny need to update it.
 dbi_query(dbc, "UPDATE zbkcommunity SET Spieler=%i, MaximaleSpieler=%i WHERE Server=^"%s^"",Spieler,MaximaleSpieler,Server)
 server_print("[AMXX] Ur Server already exist  - i update ur Informations")
 else
 // not this server found adding me in Table, 
 dbi_query(dbc, "Insert INTO zbkcommunity VALUES ('%s', %i, %i)",Server,Spieler,MaximaleSpieler)
 server_print("[AMXX] Ur Server doesn't exist - Your server was added, Welcome")
 return PLUGIN_CONTINUE;
 }
I hope u can help me to make this working

If a new server is installing my plugin, its automatical should added in my sql Database, is this done it should update his informations every 15 seconds

Last edited by schuballaa; 05-18-2007 at 12:11.
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
 



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

Forum Jump


All times are GMT -4. The time now is 10:42.


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