SA-MP Forums Archive
db_num_rows - 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: db_num_rows (/showthread.php?tid=353694)



db_num_rows - Danijel. - 24.06.2012

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


Re: db_num_rows - mkr - 24.06.2012

Код:
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.


Re: db_num_rows - ReneG - 24.06.2012

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);



Re: db_num_rows - Danijel. - 24.06.2012

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


Re: db_num_rows - ReneG - 24.06.2012

Crashes on startup? What command?


Re: db_num_rows - Danijel. - 24.06.2012

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.


Re: db_num_rows - ReneG - 24.06.2012

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


Re: db_num_rows - Danijel. - 24.06.2012

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