Raised This Month: $ Target: $400
 0% 

MySQL Prob


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 05-31-2004 , 09:34  
Reply With Quote #2

Code:
            format(query,255,"SELECT balance FROM money WHERE steamid='%s'",authid);             if(mysql_query(mysql,query) == 0)             {                 server_print("Query failed!");                 return PLUGIN_HANDLED;             }             new strBalance[32],strIncome[32];             if(mysql_nextrow(mysql) > 0)             {                 client_print(i,3,"Test:4");                 mysql_getfield(mysql,1,strBalance,31);                 mysql_getfield(mysql,3,strIncome,31);

SELECT balance FROM money WHERE steamid='%s'"

<< you are only selecting balance. So you only get one field.
You can do like this:
Code:
format(query,255,"SELECT balance FROM money WHERE steamid='%s'",authid); const FIELD_BALANCE = 1 // then later when you want to get the field: mysql_getfield(mysql,FIELD_BALANCE,strBalance,31);
So it's a nice thing to only use defined constants when referring to a field.
If you wanted to get the income field also (which I think you really wanted to do?), you would have to change the select query to something like this:
Code:
format(query,255,"SELECT balance, income FROM money WHERE steamid='%s'",authid); const FIELD_BALANCE = 1 const FIELD_INCOME = 2 // then later when you want to get the fields: mysql_getfield(mysql,FIELD_BALANCE,strBalance,31); mysql_getfield(mysql,FIELD_INCOME,strIncome,31);

I hope you get the picture, you can only get the fields which you select. and they come in the order, 1, 2 and so on... defining constants right after the select has helped me keep the fields in order nice and straight.

Might wanna take a look at syntax for SELECT: http://dev.mysql.com/doc/mysql/en/SELECT.html
Johnny got his gun is offline
 



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 07:02.


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