[Help] MySQL returning wrong result -
Maxips2 - 08.09.2012
I was trying to count number of rows from a table but for some reason I get the wrong result.
I have used this query:
pawn Код:
"SELECT COUNT(*) FROM `"TABLE_INBOX"` WHERE `linkedto` = %d AND `read` = 0"
I ran this query on phpmyadmin and I got the right result there, but not in pawn.
Here is the function, perhaps I used the mysql functions incorrectly?
pawn Код:
stock MySQL_InboxMessages(account_sqlid)
{
new
sql_result;
format(szQuery, sizeof(szQuery), "SELECT COUNT(*) FROM `"TABLE_INBOX"` WHERE `linkedto` = %d AND `read` = 0", account_sqlid);
mysql_query(szQuery);
mysql_store_result();
sql_result = mysql_num_rows();
mysql_free_result();
return sql_result;
}
I am using BlueG's MySQL Plugin version R6-2 (non cached queries)
P.S. it is always returning 1
Re: [Help] MySQL returning wrong result -
Kirollos - 08.09.2012
uhm do mysql_debug(true); at OnGameModeInit or OnFilterScriptInit and check mysql_log.txt ?
Re: [Help] MySQL returning wrong result -
Maxips2 - 08.09.2012
The debug is showing me the same result (1), I've been checking it couple of times
Quote:
>> mysql_query( Connection handle: 1 )
CMySQLHandler::Query(SELECT COUNT(*) FROM `accounts_inbox` WHERE `linkedto` = 1 AND `read` = 0) - Successfully executed.
>> mysql_store_result( Connection handle: 1 )
CMySQLHandler::StoreResult() - Result was stored.
>> mysql_num_rows( Connection handle: 1 )
CMySQLHandler::NumRows() - Returned 1 row(s)
mysql_free_result( Connection handle: 1 )
CMySQLHandler::FreeResult() - Result was successfully free'd.
|
Re: [Help] MySQL returning wrong result -
Chenko - 08.09.2012
It MIGHT be that you use mysql_free_result before you return it. I would try putting "return sql_result" and then freeing the result. I'm not that good with MySQL so I may be completely wrong.
Re: [Help] MySQL returning wrong result -
Maxips2 - 08.09.2012
It has nothing to do with it, I store the result in a variable and only then free the result.
Re: [Help] MySQL returning wrong result -
Kirollos - 08.09.2012
hmm, i think that COUNT(*) is useless here, just do format(szQuery, sizeof(szQuery), "SELECT COUNT(*) FROM `"TABLE_INBOX"` WHERE `linkedto` = %d AND `read` = 0", account_sqlid);
and return mysql_num_rows();
that should 99% work
pawn Код:
stock MySQL_InboxMessages(account_sqlid)
{
new
sql_result;
format(szQuery, sizeof(szQuery), "SELECT * FROM `"TABLE_INBOX"` WHERE `linkedto` = %d AND `read` = 0", account_sqlid);
mysql_query(szQuery);
mysql_store_result();
sql_result = mysql_num_rows();
mysql_free_result();
return sql_result;
}
Re: [Help] MySQL returning wrong result -
Maxips2 - 08.09.2012
Thank you! that worked!
However I can't quite understand why COUNT was not necessary,
would select work similiar if I am not limiting it?