mysql count
#1

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
Reply
#2

Код:
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
Reply
#3

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
Reply
#4

help me out here please
Reply
#5

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
Reply
#6

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
Reply
#7

// my bad
Reply
#8

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)".
Reply
#9

This still isn't working, It returns with 0 when it should tell me that i have 2 objects
Reply
#10

ok i fixed it, i had a minor mis type.

Thanks for the help =)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)