Raised This Month: $ Target: $400
 0% 

Calculate Sql Tabels


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-15-2007 , 15:19   Calculate Sql Tabels
Reply With Quote #1

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.



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
     }

Last edited by schuballaa; 05-15-2007 at 15:22. Reason: Please Move this Thred to the right Scripting help forum - sorry 4 posting in superhero
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
pRED*
Join Date: Dec 2006
Old 05-15-2007 , 16:53   Re: Calculate Sql Tabels
Reply With Quote #2

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")
pRED* is offline
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-15-2007 , 17:24   Re: Calculate Sql Tabels
Reply With Quote #3

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
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
Old 05-15-2007, 17:35
pRED*
This message has been deleted by pRED*.
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-15-2007 , 19:05   Re: Calculate Sql Tabels
Reply With Quote #4

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:


Important!

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

Last edited by schuballaa; 05-15-2007 at 19:16. Reason: more informations added
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
pRED*
Join Date: Dec 2006
Old 05-15-2007 , 19:35   Re: Calculate Sql Tabels
Reply With Quote #5

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
pRED* is offline
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-15-2007 , 20:06   Re: Calculate Sql Tabels
Reply With Quote #6

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

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

thaaaaanks!!!!!
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-16-2007 , 23:00   Next Problem
Reply With Quote #7

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



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"

Last edited by schuballaa; 05-16-2007 at 23:17.
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
pRED*
Join Date: Dec 2006
Old 05-17-2007 , 01:47   Re: Calculate Sql Tabels
Reply With Quote #8

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..
pRED* is offline
schuballaa
Junior Member
Join Date: May 2007
Location: Germany - Bremen
Old 05-17-2007 , 10:03   Re: Calculate Sql Tabels
Reply With Quote #9

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

Last edited by schuballaa; 05-18-2007 at 12:08. Reason: Make a new Thead because calculate works Nice thanks pRED* | NZ
schuballaa is offline
Send a message via ICQ to schuballaa Send a message via MSN to schuballaa
Reply



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:43.


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