db_num_rows
#1

I have made this for my house ownership but if i make 9999999 rows it will still return 0 rows.

Код:
qresult = db_query(Database,"SELECT * FROM `HOUSES`");
    format(Query,sizeof(Query),"%d", db_num_rows(qresult));
This topic is related to https://sampforum.blast.hk/showthread.php?tid=353664
Reply
#2

Код:
qresult = db_query(Database,"SELECT * FROM `HOUSES` WHERE 1;");
Use this query instead. You need a WHERE clause to specify what rows you want to select, and WHERE 1 will select every single row.
Reply
#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
#4

Server now crashes,when i enter the command it shuts down,did not happen before.
Reply
#5

Crashes on startup? What command?
Reply
#6

No,the code that mkr gave me,your function do not cause crash.

Now everything works but it still do not creates rows in database when i make a house.
Reply
#7

That function isn't to create rows, it's to check to see how many rows are in a table.
Reply
#8

I know,but i still have that problem,all in that topic.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)