AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calculate Sql Tabels (https://forums.alliedmods.net/showthread.php?t=55169)

schuballaa 05-15-2007 15:19

Calculate Sql Tabels
 
Hello,
i hope u can help me.
I want to Calculate (+) the inserts of Cell 1 then Save this under result1
Then the inserts of Cell 2 thens save it under result2.

Then i want to Count the enterys (see Picture) here it is =2

I don't have any idear how i do this. I tryed everything, but i a noob in this programmin language.

http://www.schubinator.de/scriptinghelp/sqlsave1.jpg

I hope u know what i mean, hope this image helps

!Very importand!

The table gets every Day 1-13 inserts more, so the do/while must count all inserts... thats why i ask u 4 help.

Here is my Code,

Code:

public read(){
 new Result:result
 result = dbi_query(dbc,"SELECT 1 FROM zbktb")
 dbi_nextrow(result)
 server_print("[AMXX] I get this: %i ",result)
 return PLUGIN_HANDLED
    }


pRED* 05-15-2007 16:53

Re: Calculate Sql Tabels
 
Code:

COUNT(*)      Returns the number of selected rows
SUM(column)      Returns the total sum of a column

So your query would be..

Code:

dbi_query(dbc,"SELECT 1,2,SUM(1),SUM(2),COUNT(*) FROM zbktb")

schuballaa 05-15-2007 17:24

Re: Calculate Sql Tabels
 
thank u very mutch, i think i need a little time to understand the small language, i get the result 181, but i try to make the rest alone with ur great and speedy help, thanks again :up:

schuballaa 05-15-2007 19:05

Re: Calculate Sql Tabels
 
I tryed a lot, i renamed the Tabels because numbers are not good to locate the error.

I tried your idea, its surely right, but i cant use it because i am too noobie.

so i post the Completly code for u, maybe u can see how to use ur idea right.

in the Documentation, I found a help tut 4 mysql, this works better than my version. But i get crasy with the calculate.

Here the Updated Code

Code:

public lesen() {
 new Sql:mysql = dbi_connect("localhost", "****", "****", "****")
//Do a select query
 new Result:res = dbi_query(mysql,"SELECT Spieler FROM zbktb")
//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
 while (res && dbi_nextrow(res)>0) {
  new qry[32]
//Get the column/field called "keyname" from the result set
  dbi_result(res, "Spieler", qry, 32)
  server_print("result1: %s", qry)
 }
 
//Free the result set
 dbi_free_result(res)
 
//Close the connection
 dbi_close(mysql)
 }

and here again what i want to do:
http://schubinator.de/scriptinghelp/sqlsave2.jpg

Important!

Every Server this plugin is installed, will be added to this table, so the server result needs everytime a new count.

pRED* 05-15-2007 19:35

Re: Calculate Sql Tabels
 
Code:
public lesen() {     new Sql:mysql = dbi_connect("localhost", "****", "****", "****")     //Do a select query     new Result:res = dbi_query(mysql,"SELECT SUM(Spieler) AS SpielerSum,SUM(MaximaleSpieler) AS MaximaleSpielerSum, COUNT(*) AS Count FROM zbktb")     //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 spieler[32],maxsp[32],count[32]         //Get the column/field called "keyname" from the result set         dbi_result(res, "SpielerSum", spieler, 31)         dbi_result(res, "MaximaleSpielerSum", maxsp, 31)         dbi_result(res, "Count", count, 31)         new ispieler=str_to_num(spieler)         new imax=str_to_num(maxsp)         new icount=str_to_num(count)         server_print("There are  %i/%i players on %i servers", ispieler,imax,icount)     }       //Free the result set     dbi_free_result(res)       //Close the connection     dbi_close(mysql) }

I havn't compiled or tested it so theres probably heaps of spelling mistakes but I think that's about right

schuballaa 05-15-2007 20:06

Re: Calculate Sql Tabels
 
Wow! i dont know how i can so much thanks

I tried this since 2 weeks (i looked at many other scripts and tried to make they work for me) but it doesn't work, now you give me the right code !exacly! i love u :up:

very very very thanks, u are my hero, now i can go on the rest is easy i hope

thaaaaanks!!!!!

schuballaa 05-16-2007 23:00

Next Problem
 
Hello again,
i have a big Problem.

It works 4 a while, but i don't know why it isn't working now ...

The Plugin isn't update the Server right.

every time the task execute the command update
it makes a new Server entery

I wan't to keep one zell per server

http://www.schubinator.de/scriptinghelp/dublicate.jpg

i hope u can help me again so fine

Code:

dbi_query(dbc, "REPLACE INTO zbkcommunity VALUES ('%s', %i, %i)",Server,Spieler,MaximaleSpieler)
I tried REPLACE, UPDATE too if i try UPDATE, nothing happens

The ip is not change thats why i use it as "ID"

pRED* 05-17-2007 01:47

Re: Calculate Sql Tabels
 
Code:

UPDATE zbkcommunity SET Spieler=%i, MaximaleSpieler=%i WHERE Server=^"%s^"",Spieler,MaximaleSpieler,Server)
You need to use the WHERE command to select which line you want to update (line is selected using the server ip as this is constant), you then update the values for this specific line..

schuballaa 05-17-2007 10:03

Re: Calculate Sql Tabels
 
Thank you 4 help pRED* | NZ
now i have a new Problem.

Moved next Problem to this Thread:
http://forums.alliedmods.net/showthread.php?t=55282

because the help tropic now is changed to if entery exist update else insert


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

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