MySQL count?
#1

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().
Reply
#2

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;
}
Reply
#3

Horrible. Use MySQL's COUNT().
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)