SA-MP Forums Archive
Getting highest field value - 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: Getting highest field value (/showthread.php?tid=347447)



Getting highest field value - BaubaS - 01.06.2012

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



Re: Getting highest field value - Jonny5 - 01.06.2012

try adding

"ORDER BY ID DESC" to your query,

should be the first row returned.

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



Re: Getting highest field value - BaubaS - 01.06.2012

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.


Re: Getting highest field value - Jonny5 - 01.06.2012

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


Re: Getting highest field value - Vince - 01.06.2012

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



Re: Getting highest field value - Kar - 02.06.2012

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



Re: Getting highest field value - Scott - 02.06.2012

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.


Re: Getting highest field value - BaubaS - 02.06.2012

Thank you everyone.


Re: Getting highest field value - BaubaS - 02.06.2012

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



Re: Getting highest field value - iggy1 - 02.06.2012

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