SQL error
#1

pawn Код:
mysql_format(mysql, query, sizeof(query), "SELECT `user`, `hours`, `minutes` FROM `players` WHERE `banned`=0 ORDER BY `hours` DESC LIMIT 10");
Above shown is a code to display the top 10 online members but it is showing until 9 rows, the 10th one says this in the server

Quote:

NULL with 0 hours and 0 minutes

here is the mysql log shows from 9th row (9th row is fine, just to show how it works until 9) but the problem starts with 10 as you could see below.



Quote:

[00:45:56] [DEBUG] cache_get_field_content - row: 9, field_name: "user", connection: 1, max_len: 24
[00:45:56] [DEBUG] CMySQLResult::GetRowDataByName - row: '9', field: "user", data: "Jason
"
[00:45:56] [DEBUG] cache_get_field_content_int - row: 9, field_name: "hours", connection: 1
[00:45:56] [DEBUG] CMySQLResult::GetRowDataByName - row: '9', field: "hours", data: "707"

[00:45:56] [DEBUG] cache_get_field_content_int - row: 9, field_name: "minutes", connection: 1
[00:45:56] [DEBUG] CMySQLResult::GetRowDataByName - row: '9', field: "minutes", data: "20"

//----------------------ERROR starts from here on

[00:45:56] [DEBUG] cache_get_field_content - row: 10, field_name: "user", connection: 1, max_len: 24
[00:45:56] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('10')
[00:45:56] [DEBUG] cache_get_field_content_int - row: 10, field_name: "hours", connection: 1
[00:45:56] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('10')
[00:45:56] [ERROR] cache_get_field_content_int - invalid datatype
[00:45:56] [DEBUG] cache_get_field_content_int - row: 10, field_name: "minutes", connection: 1
[00:45:56] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('10')
[00:45:56] [ERROR] cache_get_field_content_int - invalid datatype

Reply
#2

Returning 10 rows gives you row 0 to row 9.
There is no row 10, you're trying to get data where none exists.
Reply
#3

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Returning 10 rows gives you row 0 to row 9.
There is no row 10, you're trying to get data where none exists.
I've tried it with " DESC LIMIT 11 " and it gave me 10 outputs but the error shows in the mysql log. After all i've been using the same code for my R5 gamemode and then it was working fine.
Reply
#4

Even though you're searching for up to 10 rows, you may not get 10 rows everytime.
It's best to check the amount of rows returned from your query and loop through them.
That will prevent you accessing non-existing data/rows.

The error is pretty clear: invalid row-index.
This means row 10 doesn't exist in the result.

It's the same as accessing an array beyond it's limits.

Just try a pretty standard query like

SELECT * FROM players WHERE Name = 'Test' LIMIT 1

And try accessing row 200 or something really outside the range of your query.
You should get the same error.
Reply
#5

So that means errors would be still there while executing this code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)