db_num_rows
#3

Use this function to select the amount of rows in a database.
pawn Код:
stock db_get_rows(DB:database, tablename[])
{
    new
        query[50],
        DBResult:result,
        field[128]
    ;
    format(query, sizeof(query), "SELECT COUNT(*) FROM `%s`", tablename);
    result = db_query(database, query);
    db_get_field_assoc(result, "COUNT(*)", field, sizeof(field));
    db_free_result(result);
    return strval(field);
}
Selecting a wildcard is a waste of memory when you can use COUNT(*).

Here is an example of how to use that stock.
pawn Код:
new
    rows = db_get_rows(ExampleDB, "ExampleTableName");
printf("This table has %d rows.", rows);
Reply


Messages In This Thread
db_num_rows - by Danijel. - 24.06.2012, 08:33
Re: db_num_rows - by mkr - 24.06.2012, 08:38
Re: db_num_rows - by ReneG - 24.06.2012, 08:52
Re: db_num_rows - by Danijel. - 24.06.2012, 08:53
Re: db_num_rows - by ReneG - 24.06.2012, 08:55
Re: db_num_rows - by Danijel. - 24.06.2012, 09:06
Re: db_num_rows - by ReneG - 24.06.2012, 09:07
Re: db_num_rows - by Danijel. - 24.06.2012, 09:09

Forum Jump:


Users browsing this thread: 2 Guest(s)