SA-MP Forums Archive
MySQL count? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL count? (/showthread.php?tid=565580)



MySQL count? - Derexi - 28.02.2015

I have a function that I wrote whilst using an older version of MySQL, but now I've updated to R39-2, I can't figure out how to convert this function:

pawn Код:
format(query2, sizeof(query2), "SELECT `id` FROM `goldpots` ORDER BY `id` DESC LIMIT 1");

    mysql_query(query2);

    mysql_store_result();

    MAXGOLDPOTS = mysql_fetch_int();

    mysql_free_result();
I need to count the amount of Goldpots in the MySQL table, but when I tried to convert to the newer functions of MySQL R33+, it always counted 0 goldpots which is wrong. I don't understand how to fetch the amount of rows in the "goldpots" table as an integer, like I've done above with mysql_fetch_int().



Re: MySQL count? - BroZeus - 28.02.2015

mysql_free_result is not supported in r39-2...
To get number of rows do like this :
pawn Код:
mysql_tquery(handle, "SELECT NULL FROM `goldpots`", "MyCallback");

//now in callback
forward MyCallback();
public MyCallback()
{
        new rows, fields;
    cache_get_data(rows, fields, dbHandle);
        //now rows = number of rows use it as u want to
        return 1;
}



Re: MySQL count? - Vince - 28.02.2015

Horrible. Use MySQL's COUNT().


Re: MySQL count? - ball - 28.02.2015

Код:
mysql_query("select count(*) from goldpots");