Getting highest field value
#1

I started using r7 plugin today, and I have a question. I am trying to get highest field `ID` value, I tried to do something, but it always returns 1.

pawn Код:
mysql_function_query(iHandle, "SELECT MAX(ID) FROM `test`", true, "Test", "");
}

forward Test();
public  Test()
{
    new rows, fields, temp[12];
    cache_get_data(rows, fields);
    printf("%d zaideju", rows);
}
Reply
#2

try adding

"ORDER BY ID DESC" to your query,

should be the first row returned.

Код:
"SELECT ID FROM `test` ORDER BY ID DESC"
Reply
#3

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
try adding

"ORDER BY ID DESC" to your query,

should be the first row returned.

Код:
"SELECT ID FROM `test` ORDER BY ID DESC"
Doesnt work, returns 1 too.
Reply
#4

you mean in the server window?

i dont use the mysql plugin but i do know SQL language.
the query will return the field "ID" and its value
however you get the value from the field with pawn is beyond me.

sorry i couldn't help more,
regards
Reply
#5

Rows is the number of rows that were returned. It couldn't be anymore clear, really. cache_get_data has the same functionality as mysql_num_rows and mysql_num_fields combined. To get the data you'll need to call cache_get_row.

pawn Код:
new
    store[12],
    value;

cache_get_row(0 /* first row */, 0 /* first field */, store);
value = strval(store);

printf("%d zaideju", value);
Reply
#6

pawn Код:
forward Test();
public  Test()
{
    new rows, fields, data[12], value;
    cache_get_data(rows, fields);
if(rows > 0)
{
cache_get_row(0 /* first row */, 0 /* first field */, data);
value = strval(data);
}
    printf("%d zaideju", value);
return 1;
}
Reply
#7

Your problem is because cache_get_data returns the number of rows of data returned from the SQL query, which will always be one for the query you are performing. The query you are performing will return the highest value of the ID field which you can access with cache_get_row. Kar's solution above should work.
Reply
#8

Thank you everyone.
Reply
#9

Sorry for bumping it, didnt wanted to create another topic. I have another problem with r7 plugin, it always return NULL

pawn Код:
<....>
if (ResultID == 3)
{
    cache_get_data(iRows, iFields);
    if (iRows)
    {
        new szPassword[31];
        cache_get_field_content(0, "Slaptazodis", szPassword);
        format(szResult, 188, "Sveiki <i>%s</i>. Jыs papraрлte atsiыsti sаskaitos <u>%s</u> slaptaюodб.\n \nSlaptaюodis: <b>%s</b>", GetPlayerNameEx(playerid), GetPlayerNameEx(playerid), szPassword);
        SendMail(Email, "granderiuks@yahoo.com", "Lithuanian Trucking Administracija", "Slaptaюodis", szResult);
    }
    else
    {
    ShowPlayerDialog(playerid, CONNECTED + 1, DIALOG_STYLE_INPUT, "Slaptaюodюio priminimas", "{FFFFFF}Suveskite рios sаskaitos el. paрtа.\n{FFFFFF}Jei suvestas el. paрtas bus suvestas teisingai, laiрkas su slaptaюodюiu bus atsiыstas per artimiausiа minutж\n{FF0000}Suvestas el. paрtas yra neteisingas!", "Suvesti", "Atgal");
    }
}
Query:

pawn Код:
format(szQuery, 134, "SELECT `Email` FROM `zaidejai` WHERE `Vardas` = '%s' AND `Email` = '%s'", GetPlayerNameEx(playerid), inputtext);
mysql_function_query(iHandle, szQuery, true, "OnPlayerRequestPassword", "dssd", playerid, GetPlayerNameEx(playerid), inputtext, 3);
Reply
#10

Put this under OnGameModeInit and see what is printed in the mysql_log.txt that will be created in your server directory. Helps a lot in most cases.

pawn Код:
mysql_debug(1);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)