mysql count -
jeffery30162 - 18.01.2015
I want to find out how many objects a player has by using the count mechanism on mysql to count the number of rows that the players name comes up in the colum owner in the table objects.
Im not very good with mysql but this is what i could come up with idk if it will help you or not but here it is:
Код:
new query[300];
mysql_format(MySQLCon, query, sizeof(query), "SELECT COUNT(*) FROM objects WHERE Owner = '%s';",ObjectInfo[idxo][oOwner]);
mysql_query(MySQLCon, query);
Please fix for I can find out how many objects the player owns.
Thnak you
Re: mysql count -
CoaPsyFactor - 18.01.2015
Код:
SELECT COUNT(*) as count FROM objects WHERE Owner = '%s'
and then just get count field, or get field at index 0,
but I don't suggest using sql COUNT as it is expensive, it may take less time if you count it in pawn
Re: mysql count -
jeffery30162 - 19.01.2015
its not working. This is what im using.
Код:
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name, sizeof(name));
new query[300];
mysql_format(MySQLCon, query, sizeof(query), "SELECT COUNT(*) as count FROM objects WHERE Owner = '%s';",name);
mysql_query(MySQLCon, query);
new rows, fields, temp[120];
cache_get_data(rows, fields);
new string2[32];
format(string2, sizeof(string2), "You have %d Furniture Pieces", rows);
SendClientMessage(playerid, COLOR_YELLOW, string2);
when i have more than one object it is stuck at telling me 1
Re: mysql count -
jeffery30162 - 19.01.2015
help me out here please
Re: mysql count -
PaulDinam - 19.01.2015
pawn Код:
SELECT * FROM objects WHERE Owner = '%s'
The rows is the amount of objects the player has. This is how I do it.. Simple.
And also, you are using threaded queries so you must call a function from mysql tquery
Re: mysql count -
CoaPsyFactor - 19.01.2015
Quote:
Originally Posted by PaulDinam
pawn Код:
SELECT * FROM objects WHERE Owner = '%s'
The rows is the amount of objects the player has. This is how I do it.. Simple.
And also, you are using threaded queries so you must call a function from mysql tquery
|
This is what I mentioned, let pawno do the job

You should've post this code at the beginning
Re: mysql count -
CoaPsyFactor - 19.01.2015
// my bad
Re: mysql count -
PowerPC603 - 19.01.2015
I don't see any threaded query, as he's using mysql_query, which is a non-threaded function.
Don't use the rows variable, as mysql will only return one row, which has the count value.
Just get the value from your result at row 0, field 0 using "cache_get_row_int(0, 0)".
Re: mysql count -
jeffery30162 - 19.01.2015
This still isn't working, It returns with 0 when it should tell me that i have 2 objects
Re: mysql count -
jeffery30162 - 19.01.2015
ok i fixed it, i had a minor mis type.
Thanks for the help =)